简体   繁体   English

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

[英]Selecting first row/last row only from saved file to print

I've almost completed my code where I save data, export as pdf, all that jazz. 我几乎完成了我的代码,在其中保存数据,导出为pdf以及所有爵士乐。 I was wondering if there was a way to incorporate [excel sheet].PageSetup.PrintTitleRows = "$[firstrow]$[lastrow]"; 我想知道是否有一种方法可以合并[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. 第一行包含所有单位,报告在每一行中保存数据,但是,我只希望最后一行数据(新内容),但也需要单位行(行1)。 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 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 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 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 _ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM