VBA code to save workbook with no prompt

tispivey

New Member
Joined
Mar 10, 2022
Messages
30
Office Version
  1. 365
Platform
  1. Windows
I have a macro that converts single pages from a word document to a pdf, and saves them to a folder as "Page1, Page2, etc."

In between each conversion, I get a popup to Save, Don't Save, or Cancel.

Is there a way to auto select "Don't Save", so I don't have to select it between each conversion?


Sub savepdf()
Dim Counter As Long, Source As Document, Target As Document
Set Source = ActiveDocument
Selection.HomeKey Unit:=wdStory
Pages = Source.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
While Counter < Pages
Counter = Counter + 1
DocName = "Page" & Format(Counter) & ".pdf"
Source.Bookmarks("\Page").Range.Cut
Set Target = Documents.Add
Target.Range.Paste
Target.SaveAs FileName:=DocName, FileFormat:=wdFormatPDF
Target.Close
Wend
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Assuming your code works the way you like it, then you could try this.

VBA Code:
Application.DisplayAlerts = wdAlertsNone
Target.SaveAs FileName:=DocName, FileFormat:=wdFormatPDF
Target.Close
Application.DisplayAlerts = wdAlertsAll

(Tip: For future posts , you should try to use code tags like I did above when posting your code. It makes it easier to read.)

 
Upvote 0
Possibly a stupid question, as I am still learning how to build and edit macros, but where would it go in the above code?
 
Upvote 0
Right where this line is
VBA Code:
Target.SaveAs FileName:=DocName, FileFormat:=wdFormatPDF
 
Upvote 0
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,183
Members
452,615
Latest member
bogeys2birdies

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