PDA

View Full Version : Write a string of text to all HTM files



tomlancaster
01-18-2010, 05:31 AM
Hello

Can anyone help me with some VB Code to write automatically on file open a string of text which is appended to all files that end in file extension ".HTM", if these file extensions exist?

These files should be in a directory called "Z:\HTM"

Any assistance would be greatly appreciated! :)

Thanks
Tom

JKwan
01-18-2010, 09:32 AM
Try this

Sub test()
Dim strAppendText As String
Dim strPath As String
Dim strFile As String

strPath = "z:\htm\"
strFile = Dir(strPath & "\*.htm")

strAppendText = "Append text"

While strFile <> ""
Open strPath & strFile For Input As #1
strFileContents = Input(LOF(1), 1)
Close #1
Open strPath & strFile For Output As #1
Print #1, strFileContents & Chr(13) & strAppendText
Close #1
strFile = Dir
Wend
end sub