I am trying to write an application in VBA for Excel 97 that prints some sheets from a XLS file to a pdf file.
The application is already working, but now I would like to create a bookmark (named as the XLS sheet) for each sheet printed in the pdf. Is it possible to obtain this?
Here is the code:
Option Explicit
Const AMY_USER = "Evaluation Version Pro"
Const AMY_SERIAL = "07EFCDAB0100010020E5DB96D44F811C57E4A57B87646F5868226931E3C093AFD2E3DF34B886A8658D278AAF565A4D4CC127834D4DC892A0BE16BAD545D09D3A90D1410B31A22A81C7D6C466DF90A406C040A6"
Const NoPrompt As Integer = 1 ' do not prompt for file name
Const UseFileName As Integer = 2 ' use file name set by SetDefaultFileName else use document name
Const Concatenate As Integer = 4 ' concatenate files, do not overwrite
Const DisableCompression As Integer = 8 ' disable page content compression
Const EmbedFonts = 16 ' embed fonts used in the input document
Const BroadcastMessages = 32 ' enable broadcasting of PDF events
Sub PrintToPDF(sFilePDF As String, ParamArray aFogli())
'********************************
'** Stampa il documento su PDF **
'********************************
Dim PDFPrinter As New CDIntfEx.CDIntfEx
Dim dc As OLE_HANDLE
' this adds a new printer named PrtReltec
PDFPrinter.PDFDriverInit "PrtReltec"
dc = PDFPrinter.CreateDC
PDFPrinter.EnablePrinter AMY_USER, AMY_SERIAL
PDFPrinter.PaperSize = 9 ' set paper size to A4
PDFPrinter.Orientation = 1 ' portrait
PDFPrinter.SetDefaultPrinter ' set printer as default
PDFPrinter.DefaultFileName = sFilePDF ' set default file name
PDFPrinter.FileNameOptions = NoPrompt + UseFileName + Concatenate ' set options
'** Stampa tutti i fogli passati come parametro **
For i = 0 To UBound(aFogli)
Worksheets(aFogli(i)).PrintOut ActivePrinter:="PrtReltec"
PDFPrinter.SetBookmark dc, 0, aFogli(i) <- THIS CAN'T WORK !!!
Next
PDFPrinter.FileNameOptions = 0 ' reset all options before returning
PDFPrinter.DriverEnd
Set PDFPrinter = Nothing ' also removes the PDF printer
End Sub
Create bookmarks in PDF converted files
Hello,
Unfortunately this type of procedure is not possible with the PDF Converter because the device context (DC) created in one application can not access the device context (DC) of another application.
In order to resolve this issue I suggest that you look at our product the PDF Creator. This product gives you the ability to create bookmarks on existing PDF documents.
Thanks
Unfortunately this type of procedure is not possible with the PDF Converter because the device context (DC) created in one application can not access the device context (DC) of another application.
In order to resolve this issue I suggest that you look at our product the PDF Creator. This product gives you the ability to create bookmarks on existing PDF documents.
Thanks
Hello,
When calling SetBookmark you can use the following for the Level parameter:
0: inserts the bookmark at the same level of previous bookmark
1: inserts the bookmark at child level of previous one
-1: inserts the bookmarks at parent level of previous one
you can also use values like 2 or -2 depending on where you are in the bookmarks tree.
Hope this helps.
When calling SetBookmark you can use the following for the Level parameter:
0: inserts the bookmark at the same level of previous bookmark
1: inserts the bookmark at child level of previous one
-1: inserts the bookmarks at parent level of previous one
you can also use values like 2 or -2 depending on where you are in the bookmarks tree.
Hope this helps.