Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default 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   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default 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
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
Open, Save and close Excel 2007 file with a cmd command Hugo Pinto Excel Discussion (Misc queries) 5 March 3rd 08 10:05 PM
Macro to Open, then Close another File HROBERTSON Excel Discussion (Misc queries) 1 January 8th 07 06:41 PM
Delete/Close Excel file that is kept OPEN Jafer New Users to Excel 0 April 15th 05 05:34 AM
VBA - on a button event, open another closed file, post changes, close file Fio Excel Programming 0 March 1st 04 01:08 PM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


All times are GMT +1. The time now is 01:31 AM.

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"