Save file as pdf - VBA HELP

Status
Not open for further replies.

eekka

New Member
Joined
Apr 1, 2022
Messages
13
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Sub ExportWorkbookAsPDF()

Dim wb As Workbook

Dim ws As Worksheet

Dim filePath As String

Set wb = ActiveWorkbook

Set ws = wb.ActiveSheet

filePath = Environ("USERPROFILE") & "\Desktop\" & Left(wb.Name, InStrRev(wb.Name, ".")) & ".pdf"



ws.Columns("A").ColumnWidth = 4.78

ws.Columns("B").ColumnWidth = 13.11

ws.Columns("E").ColumnWidth = 13.11

ws.Columns("F").ColumnWidth = 9.11

ws.Columns("G:H").ColumnWidth = 10.33

ws.Columns("C:D").ColumnWidth = 13

ws.Columns("I").ColumnWidth = 10.56

ws.Columns("O").ColumnWidth = 9.22

ws.Columns("P").ColumnWidth = 10.56

ws.Columns("R").ColumnWidth = 10.33

ws.Columns("S").ColumnWidth = 9.22

ws.Columns("U").ColumnWidth = 9.22

wb.ActiveSheet.PageSetup.Orientation = xlLandscape

Dim tableRange As Range

Set tableRange = ActiveSheet.Range("A1:V13")

ActiveSheet.Rows(tableRange.Row + tableRange.Rows.Count & ":" & ActiveSheet.Rows.Count).Hidden = True

ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filePath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

End Sub

Here’s my code, it’s quite simple but basically it keeps showing error in this active workbook export. Idea is to transform the file to fit landscape view as pdf and save it to desktop. I know there’s a function to automatically save it to fit, but the issue is it doesn’t save the file to desktop as pdf
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Duplicate to: Code doesn’t work- HELP

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,140
Messages
6,123,270
Members
449,093
Latest member
Vincent Khandagale

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