Hi. I was hoping someone could help me out. I'm trying to print a sheet as
a PDF. Where I work we have a free client "PDFCreator" installed on our
machines. I can by hand print a sheet via PDFCreator and it creates a PDF.
I'm trying to be a little smart and after reading in a text file into
multiple worksheets i want to print these out. I'm trying to backup the
config ini file for PDFcreator by using NAME to rename the file. I then want
to see if a folder exists or not and if it doesn't create it. I've used a
few examples but this has given me grief. I then open the old config file
so i can copy parts of it while updating the lines I know I need to update.
I close the files and then print the worksheet, wait 5 seconds before
deleteing my new config file and restoring the old file. Code is as
follows;


Function PrintPDF(varCustomerNumber As String, varSheetNumber As Integer)
Name Environ("USERPROFILE") & "\Application
Data\PDFCreator\PDFCreator.ini" As Environ("USERPROFILE") & "\Application
Data\PDFCreator\PDFCreator.bak"
If Len(Dir(Environ("TEMP") & "\foldername")) = 0 Then MkDir
Environ("TEMP") & "\foldername"
FileNum2 = FreeFile
Open Environ("USERPROFILE") & "\Application
Data\PDFCreator\PDFCreator.bak" For Input As #FileNum2
FileNum3 = FreeFile
Open Environ("USERPROFILE") & "\Application
Data\PDFCreator\PDFCreator.ini" For Output As #FileNum3
varLineCounter_2 = 1
While Not EOF(FileNum2)
Line Input #FileNum2, varReadLine
If varLineCounter_2 = 2 Then
Print #FileNum3, "AutosaveDirectory=" & Environ("TEMP") &
"\foldername\"
ElseIf varLineCounter_2 = 3 Then
Print #FileNum3, "AutosaveFilename=" & varCustomerNumber
ElseIf varLineCounter_2 = 76 Then
Print #FileNum3, "UseAutosave=1"
ElseIf varLineCounter_2 = 77 Then
Print #FileNum3, "UseAutosaveDirectory=1"
Else
Print #FileNum3, varReadLine
End If
varLineCounter_2 = varLineCounter_2 + 1
Wend
Close FileNum2
Close FileNum3
Application.ActivePrinter = "PDFCreator on Ne00:"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"PDFCreator on Ne00:", Collate:=True
Application.Wait Now + TimeValue("00:00:05")
Kill Environ("USERPROFILE") & "\Application
Data\PDFCreator\PDFCreator.ini"
Application.Wait Now + TimeValue("00:00:01")
Name Environ("USERPROFILE") & "\Application
Data\PDFCreator\PDFCreator.bak" As Environ("USERPROFILE") & "\Application
Data\PDFCreator\PDFCreator.ini"

PrintPDF = "True"
End Function


What I am finding is when this is recalled for the second, third, fourth
sheets etc, the ini file is either renamed as .bak and therefore the first
line can't re-back it up or the kill statement doesn't work and therefore
the last rename to rename the file back doesn't work. Can anyone see any
issues with this code?

Regards,
Shane