IAC – How to convert Excel Chart to PDF using PDFWriter

A VB program that automatically converts Excel Charts to PDF
Format. A file list of Excel Charts, and a file list of the pdf names is
required.

This code sample is posted here for the general benefit of the PDF development community. Attribution and usage guidelines are as noted in the code source; please respect the wishes of the author when using this code.



Private
Sub
Form_Load(
)
'
' This program converts EXCEL format charts to PDF
' format (WIN-NT). It reads in a list of file names from a file
' and then converts those files to PDF format. It also
' edits the _pdf.ini file to allow this task to take place
'
' This program reads in a list of EXCEL file names from a file
' into an array. It also reads the corresponding list of pdf files
' into another array. The file order and names are the same, except for the
' file extenstion.
' It removes any files with a '.old' extension. It then renames
' the original PDF files with the extension '.old', and creates the
' new odf files.
'
'On Error Resume Next ' Just ignore any files that are not found
Dim
XA As
Application ' EXCEL Application
Dim
XC As
Workbook ' EXCEL Workbook
Dim
CurrentLine As
String
' Hold the .xls file name
Dim
pdfformat As
String
' Hold the .pdf file name
Dim
Count As
Integer
' Counter for array
Dim
OldName,
NewName ' Change names of converted files.
Set
XA = Excel.
Application 'Set up Excel Application in VB
Dim
PDFFilename As
String
'To hold the pdf generated file name
Dim
PDFView As
BooleanDim
i As
Integer
'used when opening _pdf.ini
PDFFilename = 'c:xlsfilesfile.pdf' 'file & path name for the pdf
generated file
'Kill 'c:xlsfilestesting*.old' 'Delete all the old pdf files
i = 1 ' size of array for the pdf files
pdfarraysize = FileLen(
'c:xlsfilespdflist.txt')
ReDim
pdfArray(
pdfarraysize)
'declare array for reading in PDF files
ReDim
pdfArrayold(
pdfarraysize)
'delclare array for renaming pdf files
Open
'c:xlsfilespdflist.txt' For
Input
As
#2 'open file for input
Cntr = 0Do
While
Not EOF(
2)
' Check for end of file, this file is the same as #2
only extensions are different. Line
Input
#2,
pdfformat
pdfArray(
Cntr)
= pdfformat 'read file names into array pdfArrayold(
Cntr)
= pdfformat & '.old' ' read file names
in, adding .old extension OldName = pdfArray(
Cntr)
: NewName = pdfArrayold(
Cntr) 'Name OldName As NewName ' Move and rename file. 'renaming original
pdf file with .old Cntr = Cntr + 1Loop
'
' Update the __pdf.ini file
'
' The variables can be set to anything you want. These are just the
values' I had in the original .ini file
'
Open
'C:WINNTSystem32SpoolDriversW32x862__pdf.ini' For
Output Asi

Print
#i,
'[Acrobat PDFWriter]'Print
#i,
'ErrFlag = 0'Print
#i,
'szTitle = file.PDF'Print
#i,
'szAuthor = adaly01'Print
#i,
'szProducer=Acrobat PDFWriter 3.03 for Windows NT'Print
#i,
'szCreator = Project1 - Microsoft; Visual; Basic; [run] -
[Form1 (Code)]'Print
#i,
'szDate=D:19990121102130'Print
#i,
'startDocTitle = file.xls'Print
#i,
'FileNameSet = 0'Print
#i,
'szSubject='Print
#i,
'szKeywords='Print
#i,
'orient = 2'Print
#i,
'bDocInfo=0'
If
PDFView = True
Then
Print
#i,
'bExecViewer = 1'
Close
i

InstallarraySize = FileLen(
'c:xlsfileslist.txt')
'get size of EXCEL
(
extentsion)
file
ReDim
InstallArray(
InstallarraySize)
Open
'c:xlsfileslist.txt' For
Input
As
#1 'open file for input
Do
While
Not EOF(
1)
' Check for end of file
Line
Input
#1,
CurrentLine ' Read line of data.
InstallArray(
Count)
= CurrentLine
Set
XC = XA.
Workbooks.
Open
(
InstallArray(
Count)
) ' Print each worksheet to the PDF
writer
For
Each
ws In
Worksheets ' The file created is 'c:xlsfilesfile.pdf
Sheets(
'BAC_chart')
.
PrintOut

'Sheets.PrintOut
Next
ws

OldName = PDFFilename: NewName = pdfArray(
Count) 'Name OldName As NewName ' Move and rename file.
Count = Count + 1Loop
XA.
Workbooks.
Close
' Close any workbooks
Close
#1 ' Close 'c:xlsfileslist.txt'
Close
#2 ' Close 'c:xlsfilespdflist.txt'

Kill
'C:WINNTSystem32SpoolDriversW32x862__pdf.ini'
Unload
Me
' Closes the form
End
Sub

You May Also Like

About the Author: Planet PDF Team

Leave a Reply