0

I want to use VB script to write to a text file and have tried using:

My.Computer.FileSystem.WriteAllText("C:\Users\Internet\test1.txt","This is new text to be added",True)

I get error -

 "Cannot use parenthesis when calling a sub".

If I remove the parenthesis, I get error -

Object required: 'My'

Have searched the help forums without luck. I'm using windows vista. could I be missing some libraries or such ?

Any help much appreciated.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
AussieCraig
  • 9
  • 1
  • 3

1 Answers1

1

This is how you can do it using vbscript. This is a simple script to create a text file and write to it

    Dim fso, objOutFile
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objOutFile = fso.CreateTextFile("Myfile.txt",True)
    objOutFile.WriteLine "Hello World"

You can modify it to create and write file to any other location. For writing to an existing file you need different method.

RanchiRhino
  • 786
  • 4
  • 21