Tool Tips

David Coverston

By David Coverston
Director-at-Large
Recognitions Chair
Membership Chair
Orlando Central Florida Chapter STC
membership@stc-orlando.org

 

This Tool tip column was sparked by a question on our chapter mailing list. In Word files, you can hyperlink to other Word documents. But if you are making PDFs from your documents, how can you maintain those links?

The problem is with this is that the hyperlinks point to other Word documents. So a link in a PDF document created from a Word document will point to the Word document you were originally linking to from the original Word document.

So, an easy solution is to PDF all the documents you want in a set, then combine them into one file. The bookmarks in the final file will link to each of the documents.

Now suppose you have lots of files to convert to PDF. Or perhaps you have to convert files on a regular basis. You really don’t want to open each file, save it as a PDF, then proceed to the next one. Well, you don’t have to. Copy and paste the code below into Word’s VBA editor, and you can save yourself a lot of time.

This macro uses Word’s Save as PDF function to create PDF files from all the Word documents in a folder. When you run it, it lets you browse to the folder where you have your files, saves them all as a PDF with the same name as the original file, then pops up a message telling you it’s all done. And it doesn’t change your original files either. In my experience, it is a faster way of creating PDF files from Word documents than using Acrobat. It will also create bookmarks from your headings.

Sub PDF_Folder()

Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim OName As String
Dim NName As String
Dim intToChange As Integer
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

‘ Get the folder containing the files
With fDialog
.Title = “Select Folder containing the documents to be PDF’ed and click Open”
.AllowMultiSelect = False
.InitialView = msoFileDialogViewDetails
If .Show <> 1 Then
MsgBox “Cancelled By User”, , “PDF Folder”
Exit Sub
End If
PathToUse = fDialog.SelectedItems.Item(1)
If Right(PathToUse, 1) <> “\” Then PathToUse = PathToUse + “\”
End With

‘Close any documents that may be open
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
FirstLoop = True

‘ This wil do both doc and docx files
myFile = Dir$(PathToUse & “*.doc*”)

While myFile <> “”

‘Open each file and run the code
Set myDoc = Documents.Open(PathToUse & myFile)

”*************************************************
”Code goes here
”*************************************************
With ActiveWindow.View
.ShowRevisionsAndComments = False
.RevisionsView = wdRevisionsViewFinal
End With

OName = ActiveDocument.FullName
intToChange = InStrRev(OName, “.”)
NName = Left(OName, intToChange 1)

ActiveDocument.ExportAsFixedFormat OutputFileName:=NName & “.pdf” _
, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=False, KeepIRM:=False, _
CreateBookmarks:=wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=False, UseISO19005_1:=False

”*************************************************

”Code ends here

”*************************************************

‘Close the file, not saving the changes.
myDoc.Close SaveChanges:=wdDoNotSaveChanges
myFile = Dir$()
Wend
MsgBox (“All Done!”)
End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.