I have macro that print Page 1, Page 14 and Page 21 with
PrintOut From:=1, To:=1
and with another macros for every other page.
Is there any way to get range of Page 1 and add code that change background colour of printed page after PrintOut ?
Related
I am using the combination of:
Application.DocumentExport SaveFileName, pjPDF, FromDate:=EarliestStart-30, ToDate:=LFin+30
and
xlbook.activesheet.OLEObjects.Add(FileName:="C:\Macros\Target-" & t & ".pdf", Link:=False, _
DisplayAsIcon:=True, IconFileName:= _
"C:\windows\Installer\{AC76BA86-1033-FFFF-7760-0E0F06755100}\_PDFFile.ico", _
IconIndex:=0, IconLabel:="Target-" & t, Left:=1082, Top:=TOffset, Width:=5, Height:=5).Select
xlbook.activesheet.OLEObjects.Placement = 1 'Move and Size with cells
with the intention of placing an icon on an excel worksheet in a specific cell. When run with these commands, I get a square Icon, measuring about 50 x 50 points with the acrobat symbol displayed above the text i.e. "189.PDF, identified as the IconLabel above. I am trying to size the icon to be 8 x 18 points so it fits inside the cell, which measures 10 x 20 points. I would prefer not to also display the Acrobat picture, jut the IconLabel text.
The Application.DocumentExport command above works exactly as it shot, saving a copy of the pdf source to a pdf, even if many pages long.
The OLEObjects.Add command works, but does not allow me to resize the icon so it will fit within the excel cell where I want to place it.
TOffset is the sum of the points from the top of the excel page to the top of the cell that I want to place the icon into. Width and Height above are supposed to represent size values in points for the Icon, but they do not work, either with or without the .OLEObjects.Placement command above.
I tried running the same 2 commands but leaving out the IconIndex field and value out of the OLEObjects string of commands. This produced desired rectangular boxes of the desired dimensions but caused some internal excel issues with being able to save the excel file--- the app did not allog me to save the file due to severe damage to the excel file. I traced the error to not having the IconIndex fieldname in the OLEObjects string. IconIndex is shown to be an optional entry on the OLEObjects.Add Microsoft page
If I assign the IconValue any integer value other than 0, then the icon is created as clear but the dimensions are the same as if IconIndex:=0.
The end goal is to take the saved PDF and place an icon holding the copy of the pdf file into a specific cell on the excel worksheet that operates similar to a button and allows me to write a short identifier to the caption for the icon.
The end result is a standalone workbook that can be distributed with need to also copy/paste all of the pdf's created by the application with it.
Would be appreciative for some leads as to how I can resize the icons, use buttons instead of OLEOPbjects.add, etc. I have tried hyperlinks, but then I have a large workbook of many, many sheets, each holding a single PDF. What I want in the end is a single worksheet which I can use to hold PDF's within Icons for all of the different printouts I have created.
Thanks
Dim TOffset As Integer
xlbook.Sheets("Task Graphics").Select
With xlbook.ActiveSheet
.Range("B2").Select
TOffset = .Range("A1:A" & row - 3).Height - 11
.Cells(row - 3, 18) = Format(LFin - 30, "mm/dd/yy")
.OLEObjects.Add(FileName:="C:\Macros\Target-" & t & ".pdf", Link:=False, _
DisplayAsIcon:=True, IconFileName:= _
"C:\windows\Installer\{AC76BA86-1033-FFFF-7760-0E0F06755100}\_PDFFile.ico", _
IconIndex:=0, IconLabel:="Target-" & t, Left:=1080, Top:=TOffset).Select
.OLEObjects.Placement = 1
.OLEObjects.ShapeRange.LockAspectRatio = msoFalse
.OLEObjects.Width = 14
.OLEObjects.Height = 10
sbDeleteAFile (SaveFileName)
End With
This answer positions the icon on the left side of the cell, leaving space in the same cell to enter some text (LFin-30), which is a date. Not sure why I had to separate the Width and Height declarations separately from the OLEObjects statement, as the OLEObjects.add reference displays that Width and Height are properties of the Icon.
The only issue I have remaining with this is that when you click the icon, the "edit" symbols (the four corners of the icon have edit circles) and if you drag the icon at all, it may resize.
I have a userform in Excel. On loading, the form pulls data from the last row of a spreadsheet. There is a button on the form to print the form.
Prior to printing the form, it updates the selection in a list box for work order status to "Assigned" and then copies this status to the spreadsheet.
Sometimes the work order status in the spreadsheet is updated to "". It is like the selection of the list box is not being recognized. It is intermittent and I have not been able to determine a pattern.
This is the code
PrintWOForm.LB_WOStatus.value = "Assigned" 'Updates WO status to Assigned
To write this to the spreadsheet I have this code
'Update WO Status to Complete if there is a date in Date Completed
'Else update Status based on Selection in WO Status list box
If PrintWOForm.TB_DateComplete = "" Then
ws.Cells(cRow, 4) = PrintWOForm.LB_WOStatus.value
Else
ws.Cells(cRow, 4) = "Complete"
ws.Cells(cRow, 23) = PrintWOForm.LB_RepairCode.value
End If
It appears when I first open the form and use the print button, which updates the selection in the list box LB_WOStatus to "Assigned", it copies a blank into cRow 4.
If I manually select a status in the list box, that time and every time forward it will work correctly even when the status is selected by the code.
I am not sure this is best the fix for my issue, but so far it appears to work well. I added the below first line of code in front the prexesting second line of code.
Me.LB_WOStatus.SetFocus 'Must SetFocus to the WOStatus list box for the application to realize the next line of code
Me.LB_WOStatus.value = "Assigned" 'Updates WO status to Assigned
I did not try using the SetFocus method previously because I read on one of these websites that this was only used to set the focus to the object for the user of the form.
What I want to do is to enable a user to delete the last row of data within a specific table. When the user does so, if they click the command button again, then the next row of data above is also deleted and so forth until this process stops at the header.
So in the image shown there are currently, 6 lines of data - the last row having numbers 160, 170 and 180 in the cells [P22, Q22 and R22 respectively]. When the user clicks the command button, these figures will be deleted. If the user then clicks the command button again then the next row of numbers above, being 130, 140 and 150 [P21, Q21 and R21 respectively] will be removed and so forth.
If say there are initially only 3 lines of data showing on the form,and the user clicks the command button, then the last figures in the row, 70, 80 and 90 [P19, Q19 and R19] would be deleted. If the command button is clicked again, then the figures in the row above, 40, 50 and 60 [P18, Q18 and R18] are deleted - process continues until stopping at the headers.
enter image description here
Any help would be appreciated, thanks
Assuming your "table" is an Excel table (and not just a range formatted to resemble a table), the code below should work.
My code assumes you have a table called "Table1" on a worksheet called "Sheet1". Change as appropriate for you.
Option Explicit
Private Sub DeleteLastRowInTable()
With ThisWorkbook.Worksheets("Sheet1").ListObjects("Table1")
If .ListRows.Count > 0 Then
.DataBodyRange.Rows(.DataBodyRange.Rows.Count).EntireRow.Delete
End If
End With
End Sub
The If statement is meant to prevent errors when the table has no data (beneath its headers).
I have a VBA form which is used to enter data on a sheet. I am currently coding the form so as it will load any data already existing in the sheet back into the form.
For simple text strings it works perfectly.
e.g.
ReqSetup.ReqText = Application.Worksheets("Req Sheet").Range("F11").Value
However, I have some combo boxes, that on the form, when they are selected will enter a number in the corresponding cell.
Fail 1. - Run Time Error 380 - Invalid property value.
ReqSetup.MinPerKgCB = Application.Worksheets("Req Sheet").Range("C27").Value
Fail 2.
Dim MinPerKg As Range
Set MinPerKg = Application.Worksheets("Req Sheet").Range("C27")
ReqSetup.MinPerKgCB = MinPerKg
I'm obviously doing something really simple wrong but I can't work out what it is!!
Kind Regards!
I have some combo boxes, that on the form, when they are selected will
enter a number in the corresponding cell
Then you'd need to do the opposite of your code attempt, i.e.:
Worksheets("Req Sheet").Range("C27").Value = ReqSetup.MinPerKgCB.Value
That you'd better wrap inside a check that any combobox value is actually selected :
With ReqSetup.MinPerKgCB
If .ListIndex <> -1 Then Worksheets("Req Sheet").Range("C27").Value = .Value
End With
I've got an issue with my listbox. In the user form initialize event I'm using the following code to populate it:
RecordSelectionBox.List = WorkingCopy.Worksheets(1).Range("A2:P20").Value
Which works out fine. I have column width adjustments which also work out fine. Once the user has selected a record, a line from the listbox I'm setting the captions of a bunch of labels to the value of the listbox columns. It fills out label captions 1 to 15 just fine. When it hits 16 I get an error "Could Not Get the Column Property. Invalid Argument" "Run-time error '-2147024809 (80070057)'"
Here is the code:
Explanation.Caption = RecordSelectionBox.Column(16)
a debug.print of RecordSelectionBox.ColumnCount shows that I indeed have 16 columns. The explanation field is the longest of the fields I'm using, but I'm not sure that I see how that would become an issue. If anyone has an idea, I'm all ears.
That is because the First Column of the listbox starts with 0
Your first Label should be
Label1.Caption = RecordSelectionBox.Column(0)
and the 16th should be
Explanation.Caption = RecordSelectionBox.Column(15)