Need VBA to interact with PDFMaker addin

bruty

Active Member
Joined
Jul 25, 2007
Messages
451
Hi all,

I have an Excel file with internal links that needs to be saved as PDF. I have found a way to manually do this using the PDFMaker add-in, but am now trying to automate this but am really struggling. I've tried to Google some results but have had no luck there either.

Does anyone have any code that can call the PDFMaker, select some sheets and create the pdf from there?

Thanks in advance.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I have managed to get the following code to open up the PDFMaker, but for some reason when I click on the Convert to PDF button it prints it to PDF instead, losing the links anyway:

Code:
Sub ExportToPDF()
Dim pdfname, i, a
Dim pmkr As AdobePDFMakerForOffice.PDFMaker
Dim stng As AdobePDFMakerForOffice.ISettings
If Not ActiveWorkbook.Saved Then
  MsgBox "You must save the document before converting it to PDF", vbOKOnly, ""
  Exit Sub
End If
Set pmkr = Nothing ' locate PDFMaker object
For Each a In Application.COMAddIns
  If InStr(UCase(a.Description), "PDFMAKER") > 0 Then
    Set pmkr = a.Object
    Exit For
  End If
Next
If pmkr Is Nothing Then
  MsgBox "Cannot Find PDFMaker add-in", vbOKOnly, ""
  Exit Sub
End If
pdfname = ActiveWorkbook.FullName ' construct output name
i = InStrRev(pdfname, ".")
pdfname = IIf(i = 0, pdfname, Left(pdfname, i - 1)) & ".pdf"
' delete PDF file if it exists
If Dir(pdfname) <> "" Then Kill pdfname
pmkr.GetCurrentConversionSettings stng
stng.AddBookmarks = True
stng.AddLinks = True
stng.AddTags = True
stng.ConvertAllPages = True
stng.CreateFootnoteLinks = True
stng.CreateXrefLinks = True
stng.OutputPDFFileName = pdfname
stng.PromptForPDFFilename = False
stng.ShouldShowProgressDialog = True
stng.ViewPDFFile = False
pmkr.CreatePDFEx stng, 0 ' perform conversion
If Dir(pdfname) = "" Then ' see if conversion failed
  MsgBox "Could not create " & pdfname, vbOKOnly, "Conversion failed"
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,522
Messages
6,114,112
Members
448,549
Latest member
brianhfield

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