Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Text into Several Files

Status
Not open for further replies.

ToeKnee2

Programmer
Jun 8, 2006
21
GB
Hi All,

I have a bit of code that should go through every file in the folder specified and insert a bit of text. This is fine, except it doesn't work.

Could anyone advise why this doesn't work?

Code:
Sub replacetxt()
Dim fso, fol, f
Dim a As String

Set fso = CreateObject("Scripting.filesystemobject")
Set fol = fso.GetFolder("C:\Test\")


For Each f In fol.Files
    a = FreeFile
    Open f.Name For Output As a
    
    Print #a, "This is new text"
    Close a
Next f

Set f = Nothing
Set fol = Nothing
Set fso = Nothing
End Sub

thanks in advanced.
 
Freefile, Open .. For .. As, Print # and Close are VB or VBA, not VBS !

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top