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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,224,814
Messages
6,181,126
Members
453,021
Latest member
Justyna P

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