仅从已保存的文件中选择第一行/最后一行进行打印

时间:2015-06-03 19:45:04

标签: excel vba excel-vba

我几乎完成了我保存数据的代码,导出为pdf,所有爵士乐。我想知道是否有办法将[excel sheet].PageSetup.PrintTitleRows = "$[firstrow]$[lastrow]";合并到我的程序中。我不确定这是否应该以某种方式进行操纵。第一行包含所有单元,报告在每行中保存数据,但是,我只想要最后一行数据(新内容),但也需要单元行(第1行)。这是我的代码,不完全确定它放在哪里(可能接近结束):

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

1 个答案:

答案 0 :(得分:0)

这是有效的(最后)我只是再次复制/粘贴。

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

相关问题