Trying to Append File using the example in excel but not working


S

Susan Hayes

Hello

Im trying to open a file and if it does not exist - then create it, and write to the end of it.
I have copied the example from help on "opentextfile method" and it does not work
Can anyone help
Thanks in advance
Susan

Sub OpenTextFileTest
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\testfile.txt", ForAppending,TristateFalse)
f.Write "Hello world!"
f.Close
End Sub



Aswell is it possible to insert a row without inserting it into column A?
ie column A has numbers 1,2,3... whcich are passed downward as the rows are inserted.
I have found a way around it by calculating this series in a do while loop. I would perfer to avoid this!
Thanks Again
Susan
 
Ad

Advertisements

D

Dave Peterson

I defined forappending = 8 and it worked ok:

Const ForReading = 1, ForWriting = 2, ForAppending = 8, TristateFalse = 0

(don't forget tristatefalse if you have Option explicit turned on.)
 
Ad

Advertisements

D

Dave Peterson

Not sure what you mean for the second question, but maybe you could just insert
columns B:IV and shift down?

(or just renumber column A?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top