LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Shane Malden
 
Posts: n/a
Default Issues with saving text file

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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting excel to text file Exceluser Excel Discussion (Misc queries) 1 June 22nd 05 11:26 PM
how do I convert an excel file to a flat text file Lannutslp Excel Discussion (Misc queries) 1 June 3rd 05 10:17 AM
Convert excel file to flat text file Lannutslp Excel Discussion (Misc queries) 1 June 1st 05 03:48 AM
Convert excel file to flat text file Gary's Student Excel Discussion (Misc queries) 0 June 1st 05 12:17 AM
Export excel file to semicolon delimited text file capitan Excel Discussion (Misc queries) 5 April 7th 05 03:06 AM


All times are GMT +1. The time now is 10:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"