Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
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


Reply
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
issues while saving Ricknot Excel Discussion (Misc queries) 0 November 24th 06 05:31 PM
Text file saving, setting file origin mauddib Excel Discussion (Misc queries) 0 May 25th 06 02:50 PM
saving an excel file as text without text in quotes John Excel Discussion (Misc queries) 2 December 6th 05 06:20 PM
Issues with saving text file Shane Malden Excel Worksheet Functions 0 October 25th 05 04:37 PM
saving an excel file as an ASCII text file without delimiters Sewellst Excel Programming 4 January 7th 05 01:41 PM


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

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

About Us

"It's about Microsoft Excel"