Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 11-07-2017, 03:14 AM
FionaMcKenzie FionaMcKenzie is offline Saving and creating PDF at once Windows 10 Saving and creating PDF at once Office 2016
Novice
 
Join Date: Oct 2017
Location: Surrey, United Kingdom
Posts: 14
FionaMcKenzie is on a distinguished road
Default

Hi again,

I was hesitant on the whole Save point... There is a BeforeSave but not an AfterSave event in Word. The only way I could think of doing the PDF save after the Save completed was to evoke a Windows change to evoke the WindowsEvent in Word & do the PDF save then. All very, very mucky. So not a solution! It's such a pity there is no AfterSave event!

However, you can override the Word FileSave process.
Note: This means your program cannot have bugs.

If you SaveAs on an existing file to a new file name, you would have to process your PDF save manually when doing so. But this will trap the save when you want to create your PDF backups.

I've written code for you with comments. You can add this to your template, but be careful with Word overrides.

Let me know if it helps you with your PDF save request though.

Kind regards
Fiona

Option Explicit

Public Sub FileSave()

' Note: FileSave overrides Word's FileSave command!

On Error GoTo ErrorHandler

With ActiveDocument

' Check whether it has a path meaning it's been saved before
If .Path = vbNullString Then

' Show the SaveAs dialog
Word.Dialogs(wdDialogFileSaveAs).Show

Else

' Save the document
.Save
End If

' Was the file saved in the SaveAs Dialog
If .Saved = True Then

' You will need ensure only documents based on this template
' are saved as PDF. Save your source document as a *.dotm
' When you create new instances of the template, this code will run
If .AttachedTemplate = ThisDocument Then

' You don't want to save PDFs of the template, just documents
If LCase(Right(.FullName, 5)) = ".docx" Then

' Not sure if you want to check before saving the PDF?
If MsgBox("Would you like to save a PDF copy?", _
vbYesNo, "Save PDF version") = vbYes Then

' It's active already though
.Activate

' Call the procedure you were given to create the PDF
Call PDFSave.SaveAsDocX_PDF

End If
End If
End If
End If
End With

Exit Sub
ErrorHandler:
' Quite crucial if an error occurs!
MsgBox "An error occurred on FileSave!" & vbCr & vbCr & _
Err.Number & " " & Err.Description, vbOKOnly + vbExclamation, "FileSave Error"
Err.Clear
End Sub
Reply With Quote
 

Tags
pdf creator, saving, saving options



Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving and creating PDF at once Problems with creating and saving word templates smd89 Word 2 03-30-2016 06:38 AM
Problem with saving as .PDF benoitbri Word 5 02-12-2016 07:31 AM
Saving and creating PDF at once Saving as pdf danielraviolo Word 5 06-19-2015 09:46 PM
Saving VBA skib PowerPoint 0 02-18-2011 12:59 AM
Saving backup prestoaa Outlook 0 12-13-2010 08:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:17 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft