Convert multiple documents with hyperlinks with a VBA macro

This Forum is for the use of End Users requiring help and assistance for Tracker Software's OFFice2PDF and MS Office Addin Applications - supplied with PDF-XChange.

Moderators: Tracker Support, TrackerSupp-Daniel, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Tracker Supp-Stefan

Post Reply
Thomas Roesner
Posts: 1
Joined: Thu Feb 20, 2014 3:17 pm

Convert multiple documents with hyperlinks with a VBA macro

Post by Thomas Roesner » Thu Feb 20, 2014 3:40 pm

Dear all,
from time to time i have to convert a lot of small word documents wich have crossreferencing hyperlinks to each other. Due to the fact that we dont know how to link to an anchor in the middle of an other document we have to split a large doc file in a lot of smaller files.

If i try to convert the docx files via the toolbar i get a set of well linked pdf files for the price of a lot of manually work.

If i try with office2pdf5.exe i'll miss the hyperlinks, which makes the result unusable for my needs. It seems, that the office plugin can be configured in more detailes.

Unfortunately i dont know how to script this with VBA. Is there a way to make calls to the plugin? Can you please give an example?

Or is ther a way to configure office2pdf5 as flexible as the office plugin?

Kind Regards
Thomas Roesner

User avatar
Will - Tracker Supp
Site Admin
Posts: 6668
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK

Re: Convert multiple documents with hyperlinks with a VBA ma

Post by Will - Tracker Supp » Fri Feb 21, 2014 1:10 am

Hi Thomas,

I'm afraid that currently, this is not possible. However, we should be releasing the new version of Office2PDF[6] and that is capable of preserving such links, as it uses the Office Addin. We hope to release this with the next build of the Editor - for now, I don't have any information as to when that will be.

If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.

Best regards

Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.

Willy Van Nuffel
Posts: 1377
Joined: Wed Jan 18, 2006 12:10 pm

Re: Convert multiple documents with hyperlinks with a VBA ma

Post by Willy Van Nuffel » Sat Feb 22, 2014 10:50 am

Untill you will be able to do this job via PDF-XChange, you could use the built-in "Save as" > "PDF" of Microsoft Word.

I hope you have a little bit experience with Visual Basic for Applications...

In that case you can create a macro with following content (that you will have to modify to your own needs).
It will make a PDF of every *.docx that is in the given directory. Hyperlinks will be converted. For the naming it will use the same name as the Word document, by stripping off the ".docx" and replace it with the ".pdf" extension.

Sub LoopDirectory()

Dim vDirectory As String
Dim oDoc As Document

vDirectory = "C:\Willy\"

vFile = Dir(vDirectory & "*.docx")

Do While vFile <> ""
Set oDoc = Documents.Open(FileName:=vDirectory & vFile)
DocName = Left(oDoc, Len(oDoc) - 5) & ".pdf"

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
DocName, ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
True, UseISO19005_1:=False

oDoc.Close SaveChanges:=False
vFile = Dir

End Sub

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13324
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Convert multiple documents with hyperlinks with a VBA ma

Post by Tracker Supp-Stefan » Mon Feb 24, 2014 2:23 pm

Thanks for the idea Willy,


Post Reply