Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Text file open and close VBA
Hi
I am new to VBA development, I have text file and opening text file in my VBA to read. After that i want to Add new line, so i Open it for output mode, (I will create delete existing and create new file that is ok for me). Here is my code Open sXferFile For Output As #1 While Not EOF(1) Line Input #1, stemp sFileName = stemp Line Input #1, stemp ' sProcessDate = CDate(STEMP) sProcessDate = stemp Wend close #1 -- after this sfnum = freefile Open sXferFile For Output As #sFnum write #sfnum, "Over" close #sfnum I am getting Path/file error when i open it after closing text file. Need help? Thanks kalyan |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Text file open and close VBA
First issue --- You can't read (line input #1) an output, you can only read
files open for input. "Karpgam" wrote in message ... Hi I am new to VBA development, I have text file and opening text file in my VBA to read. After that i want to Add new line, so i Open it for output mode, (I will create delete existing and create new file that is ok for me). Here is my code Open sXferFile For Output As #1 While Not EOF(1) Line Input #1, stemp sFileName = stemp Line Input #1, stemp ' sProcessDate = CDate(STEMP) sProcessDate = stemp Wend close #1 -- after this sfnum = freefile Open sXferFile For Output As #sFnum write #sfnum, "Over" close #sfnum I am getting Path/file error when i open it after closing text file. Need help? Thanks kalyan |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Text file open and close VBA
Hi
Sorry I wrongly pasted my code actual code will be like this FOLLOWING PART WORK FINE Open sXferFile For input As #1 While Not EOF(1) Line Input #1, stemp sFileName = stemp Line Input #1, stemp sProcessDate = stemp Wend close #1 AFTER CLOSE, WHEN I OPEN FOR OUTPUT I GOT ERROR sfnum = freefile Open sXferFile For Output As #sFnum write #sfnum, "Over" close #sfnum I KNOW IF I OPEN EXISTING FILE FOR OUTPUT, THAT WILL DELETE AND RECREATE THAT IS FINE, BUT IT IS NOT BEHAVING LIKE THAT, SIMPLY GIVE ERROR Path/file error THANKS KALYAN -----Original Message----- First issue --- You can't read (line input #1) an output, you can only read files open for input. "Karpgam" wrote in message ... Hi I am new to VBA development, I have text file and opening text file in my VBA to read. After that i want to Add new line, so i Open it for output mode, (I will create delete existing and create new file that is ok for me). Here is my code Open sXferFile For Output As #1 While Not EOF(1) Line Input #1, stemp sFileName = stemp Line Input #1, stemp ' sProcessDate = CDate(STEMP) sProcessDate = stemp Wend close #1 -- after this sfnum = freefile Open sXferFile For Output As #sFnum write #sfnum, "Over" close #sfnum I am getting Path/file error when i open it after closing text file. Need help? Thanks kalyan . |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Text file open and close VBA
And how is freefile populated?
wrote in message ... Hi Sorry I wrongly pasted my code actual code will be like this FOLLOWING PART WORK FINE Open sXferFile For input As #1 While Not EOF(1) Line Input #1, stemp sFileName = stemp Line Input #1, stemp sProcessDate = stemp Wend close #1 AFTER CLOSE, WHEN I OPEN FOR OUTPUT I GOT ERROR sfnum = freefile Open sXferFile For Output As #sFnum write #sfnum, "Over" close #sfnum I KNOW IF I OPEN EXISTING FILE FOR OUTPUT, THAT WILL DELETE AND RECREATE THAT IS FINE, BUT IT IS NOT BEHAVING LIKE THAT, SIMPLY GIVE ERROR Path/file error THANKS KALYAN -----Original Message----- First issue --- You can't read (line input #1) an output, you can only read files open for input. "Karpgam" wrote in message ... Hi I am new to VBA development, I have text file and opening text file in my VBA to read. After that i want to Add new line, so i Open it for output mode, (I will create delete existing and create new file that is ok for me). Here is my code Open sXferFile For Output As #1 While Not EOF(1) Line Input #1, stemp sFileName = stemp Line Input #1, stemp ' sProcessDate = CDate(STEMP) sProcessDate = stemp Wend close #1 -- after this sfnum = freefile Open sXferFile For Output As #sFnum write #sfnum, "Over" close #sfnum I am getting Path/file error when i open it after closing text file. Need help? Thanks kalyan . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Open, Save and close Excel 2007 file with a cmd command | Excel Discussion (Misc queries) | |||
Macro to Open, then Close another File | Excel Discussion (Misc queries) | |||
Delete/Close Excel file that is kept OPEN | New Users to Excel | |||
VBA - on a button event, open another closed file, post changes, close file | Excel Programming | |||
Automate open file, update links, run macro, close and save file | Excel Programming |