Using Export to PDF Issue

ExcelNewbie29

New Member
Joined
Jan 5, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I am at a loss for how to fix this issue I am having. I am sure it is something simple, but I think I have stared at it too long to understand what mistake I am making. As the name indicates, I am new to VBA and learning in order to make my life and my coworkers lives easier.

Context: We have a report that we have to produce ~40 of each month. Each one is slightly different than the others, as they are presented in various groups and meetings. I have 2 working macros and 1 that does not work - the export to PDF macro. I am looking to click a button (shape designed and macro assigned already) and that will automatically export the active sheet to PDF and name it (Cell B5) (Cell I3) FDAF Deck. It is ok for it to go to the default folder, since I am unable to save it to a shared drive due to company security settings. The goal is that this should allow myself/coworkers to create the presentation sheet that is needed and have it saved based on the meeting group they are presenting to and the month/year.

Here is the code. Again, new to VBA so feel free laugh at the very rudimentary code.

Sub Export_To_PDF()
'Create and Assign Variables
Dim saveLocation As String
saveLocation = "Range(B5).Value & Range(I3).Value & FDAF Deck"

'ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=saveLocation, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=5, _
OpenAfterPublish:=True
End Sub


1672944397900.png
1672944428302.png

I am unsure why this will not work for me. I a nearly identical code written into the previous version of this file, but I created a secondary version to change some of the formatting and such without losing the first one. The other codes seem to work just fine, so it is only Export to PDF that is causing me heartburn. Any/all assistance is appreciated!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
untested but see part of your code is commented out. try

VBA Code:
Sub Export_To_PDF()
'Create and Assign Variables
Dim saveLocation As String
saveLocation = "Range(B5).Value & Range(I3).Value & FDAF Deck"

With ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=saveLocation, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=5, _
OpenAfterPublish:=True
End with
End Sub
 
Upvote 0
untested but see part of your code is commented out. try

VBA Code:
Sub Export_To_PDF()
'Create and Assign Variables
Dim saveLocation As String
saveLocation = "Range(B5).Value & Range(I3).Value & FDAF Deck"

With ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=saveLocation, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=5, _
OpenAfterPublish:=True
End with
End Sub
Still having issues with the VBA code. Tried the one above to no avail. Here is where I am at:

VBA Code:
Sub ExportToPDF()
'Create and assign variables
Dim saveLocation As String
saveLocation = "Range(B5).Value & Range(I3).Value & FDAF Deck"

ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=saveLocation, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=False, _
    IgnorePrintAreas:=False, _
    From:=1, _
    To:=2, _
    OpenAfterPublish:=True

End Sub

The code break I am getting is coming in on the OpenAfterPublish:=False line. I have no clue why that line would be causing me so many issues.

Thought I had gotten it fixed, but now it does not want to work with me again. Very frustrating.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,349
Members
449,155
Latest member
ravioli44

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