xls to PDF vba code right margin not working

dcrighton

New Member
Joined
Nov 24, 2014
Messages
31
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
 
it still seems to be selective sometimes it doesn't center and other times it does maybe there is white space in a cell to the right causing it to think it is centered. It is really odd the issues I'm having.
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top