I've almost completed my code where I save data, export as pdf, all that jazz. I was wondering if there was a way to incorporate [excel sheet].PageSetup.PrintTitleRows = "$[firstrow]$[lastrow]";
into my program. I'm not sure if this should be manipulated in some way. The first row holds all the units and the report saves data in each row, however, I only want the last row of data (new stuff), but with the unit row (row 1) as well. Here's my code, not entirely sure where it put it (proably near the end):
Sub Save_History()
'copies data from calculation page
Sheets("Simple Calculation").Select
Range("A2:I2").Select
Selection.Copy
Sheets("Media History").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Application.DisplayAlerts = False`
' Check for year folder and create if needed
If Len(Dir("C:blah\" & Year(Date), vbDirectory)) = 0 Then
MkDir "C:blah\" & Year(Date)
End If
' Check for month folder and create if needed
If Len(Dir("C:blah\" & Year(Date) & "\" & MonthName(month(Date), False), vbDirectory)) = 0 Then
MkDir "C:blah\" & Year(Date) & "\" & MonthName(month(Date), False)
End If
' Check for day folder and create if needed
If Len(Dir("C:blah\" & Year(Date) & "\" & MonthName(month(Date), False) & "\" & Day(Date), vbDirectory)) = 0 Then
MkDir "C:blah\" & Year(Date) & "\" & MonthName(month(Date), False) & "\" & Day(Date)
End If
strFilePath = "C:blah\" & Year(Date) & "\" & MonthName(month(Date), False) & "\" & _
Format(Date, "mm.dd.yy") & "_" & Format(Time(), "hh.mm.ssAM/PM") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=x1TypePDF, Filename:=strFilePath, _
Quality:=x1QualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True _
Application.DisplayAlerts = True
' Popup Message
MsgBox "File Saved As:" & vbNewLine & strFilePath
End Sub
Here's what worked (finally) I just Copied/pasted again.
Sub Save_History()
Sheets("Simple Calculation").Select
Range("A2:I2").Select
Selection.Copy
Sheets("New Media Report").Select
Range("A1").End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'copies data from calculation page Sheets("Simple Calculation").Select
Range("A2:I2").Select
Selection.Copy
Sheets("Media History").Select
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Application.DisplayAlerts = False
' Check for year folder and create if needed
If Len(Dir("C:blah\\" & Year(Date), vbDirectory)) = 0 Then
MkDir "C:blah\\" & Year(Date)
End If
' Check for month folder and create if needed
If Len(Dir("C:blah\\" & Year(Date) & "\\" & MonthName(month(Date), False), vbDirectory)) = 0 Then MkDir "C:blah\\" & Year(Date) & "\\" & MonthName(month(Date), False) End If
' Check for day folder and create if needed If Len(Dir("C:blah\\" & Year(Date) & "\\" & MonthName(month(Date), False) & "\\" & Day(Date), vbDirectory)) = 0 Then MkDir "C:blah\\" & Year(Date) & "\\" & MonthName(month(Date), False) & "\\" & Day(Date) End If
strFilePath = "C:blah\\" & Year(Date) & "\\" & MonthName(month(Date), False) & "\\" & _ Format(Date, "mm.dd.yy") & "_" & Format(Time(), "hh.mm.ssAM/PM") & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=x1TypePDF, Filename:=strFilePath, _ Quality:=x1QualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True _
Application.DisplayAlerts = True
' Popup Message MsgBox "File Saved As:" & vbNewLine & strFilePath
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.