Bellow is a vba code I have used to print sheets from multiple excel files. It works great except the right margin doesn't go to 0.5. I would like the top, Left, Right margins all to be 0.5 and if needed the excel sheet data can be scaled to make the margins in the PDF. I do not want the bottom margin to be set. Any help is much appreciated.
Thank you,
Devin
Sub PrintSheetToPDF()
shName = "Weld Map "
With Application.FileDialog(3)
.AllowMultiSelect = True
.Show
If .SelectedItems.Count = 0 Then
MsgBox "No file selected!"
Else
For i = 1 To .SelectedItems.Count
Set wb = Workbooks.Open(.SelectedItems(i))
Set ws = wb.Sheets(shName)
pdfName = Left(wb.FullName, InStrRev(wb.FullName, Chr(46))) & "pdf"
With ws.PageSetup
.PrintArea = "$A$1:$W$20"
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
'.BottomMargin = Application.InchesToPoints(0.5)'
End With
ws.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=pdfName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
wb.Close False
Next i
End If
End With
Thank you,
Devin
Sub PrintSheetToPDF()
shName = "Weld Map "
With Application.FileDialog(3)
.AllowMultiSelect = True
.Show
If .SelectedItems.Count = 0 Then
MsgBox "No file selected!"
Else
For i = 1 To .SelectedItems.Count
Set wb = Workbooks.Open(.SelectedItems(i))
Set ws = wb.Sheets(shName)
pdfName = Left(wb.FullName, InStrRev(wb.FullName, Chr(46))) & "pdf"
With ws.PageSetup
.PrintArea = "$A$1:$W$20"
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
'.BottomMargin = Application.InchesToPoints(0.5)'
End With
ws.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=pdfName, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
wb.Close False
Next i
End If
End With