Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    Omaha, Nebraska
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Compile Word through VBA (Word 2000)

    This may have been asked before, but is there a way to compile a word document using VBA?

    Here's what I'm trying to do. I have a listing of documents in a folder that some have code in them and some don't. I have code that will process each document and remove the code module. However, when you reopen the documents, you are still prompted that they have macros in them (I'm using Medium Security). If I manually do a debug | compile on the document, I'm not prompted any more that there are macros in the document. I need a way to do this automatically because I can't go through each document and recompile them by hand.

    Any suggestions?
    Tks in advance!

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Compile Word through VBA (Word 2000)

    I don't know whether you can compile a file via code but another way to achieve the same aim is to copy the contents of that file into a blank file and then overwrite the original file. You may also need to include, copying across styles, page setup and header/footers but it should work reasonably well.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Location
    Omaha, Nebraska
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Compile Word through VBA (Word 2000)

    Since I hadn't found any way to compile the file via code either, I started looking into other ways to remove the macros from the files.

    I found that if you save the document as and RTF file the macros are removed. You then need to close the file, reopen it, and then resave the RTF file back to a DOC file.
    This effectively removes the macros and preserves all of my other styles and formatting.

    NOTE: If you are not wanting to rename the file, it appears that you actually must close the RTF file prior to resaving the document to the original name. Otherwise, the macros remain.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Compile Word through VBA (Word 2000)

    <hr>If you are not wanting to rename the file, it appears that you actually must close the RTF file prior to resaving the document to the original name. Otherwise, the macros remain.<hr>
    For what it's worth, the reason for this is that when you do a SaveAs to another format, Word keeps the same owner file (~$Filename.doc) open & copies the changes to a temp file. It's only after you close the new file that the changes are copied & the temp files are deleted.

Posting Permissions

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