У меня есть простая подпрограмма для сохранения диапазона в формате PDF в указанной пользователем папке. Проблема в том, что PDF-файл имеет 0 полей сверху. Мне нужен запас в 0,25 дюйма. Что я делаю не так?
Private Sub btnPrintJobWorksheet_Click()
Dim folderPath As String, filePath As String, fileName As String, jobNumber, rng As String
Dim ws As Worksheet
'Get the Job Number and create the File Name
jobNumber = ThisWorkbook.Names("JOBNUMBER").RefersToRange.Value
fileName = "Job Worksheet - " & jobNumber & ".pdf"
'Allow the user to select the folder to save to
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
folderPath = .SelectedItems(1)
filePath = folderPath & "\" & fileName
End If
End With
'Retrieve the Print Area
Set ws = ThisWorkbook.ActiveSheet
rng = CStr(ws.PageSetup.printArea)
'Set the Page Margins
With ws.PageSetup
.CenterHorizontally = True
.TopMargin = 0.25
.RightMargin = 0.2
.BottomMargin = 0.25
.LeftMargin = 0.2
.HeaderMargin = 0.1
.Zoom = False
.FitToPagesTall = 1
.FitToPagesWide = 1
End With
'If No Print Area was found, then set the Print Area range to its default value
If (Len(rng) < 2) Then
rng = "$B$1:$L$51"
End If
'If we have a File Path and we have a range, then save the PDF
If Len(filePath) > 0 And Len(rng) > 2 Then
ws.Range(rng).ExportAsFixedFormat _
Type:=xlTypePDF, fileName:=filePath, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, openAfterPublish:=True
End If
Set ws = Nothing
End Sub