Consulting

Results 1 to 2 of 2

Thread: Write a string of text to all HTM files

  1. #1

    Write a string of text to all HTM files

    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

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Try this
    [vba]
    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

    [/vba]
    Last edited by JKwan; 01-18-2010 at 09:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •