0

I've been working with many looooong RTF files filled with exam questions. I edit these in MS Word 2010. I've written a macro that will renumber those questions since the original numbering is far from sequential.

What is the best way to load that macro into each of the many RTF files so that I can run it for each?

I have saved the macro as a .bas file which can be loaded into Word for other documents, but it's a bit cumbersome to do that, so I'm wondering if there's a better way.

The macro will eventually be used by other people, so I'd rather not walk them through Word's VB macro editor screens if I can help it.

1 Answer 1

1

Q: How should I load a macro when editing an RTF file?

  • Save this code in the normal.dot template
  • Replace the messagebox with your own code
    The code will only be executed if you open an existing .rtf file or create a new .rtf file

    Private Sub Document_Open()
        Call mycode
    End Sub
    
    Private Sub Document_New()
        Call mycode
    End Sub
    
    Sub mycode()
        If Not ActiveDocument.Name Like "*.rtf" Then Exit Sub             
        MsgBox "Insert your code here"            
    End Sub
    

Q: I want to share my Word macro with others automatically

  • Copy your normal.dot to a shared network so others can get it from there.
    The normal.dot is usually stored in %appdata%\Microsoft\Templates
    (differs for localized Office versions)

  • or you copy the file automatically using windows batch together with xcopy or robocopy.
    But this method needs access to drive C of every coworker

3
  • Thanks for those tips. I don't think I'll make it an autorun macro since that would probably drive everyone crazy, especially if they happen to open an unrelated RTF someday. I wondered about creating a normal.dotm but then that might overwrite the other people's customizations if they've already got one. But I wonder if the same sort of technique--i.e., using a .dotm macro template file--would work instead.
    – yukondude
    Commented Jan 29, 2013 at 16:13
  • @yukon, shouldn't you want something that loads automatically but doesn't run immediately? You could put it in normal.dot, but set it to define a keyboard shortcut or add an entry to the Tools > Macros menu that users can invoke when needed.
    – alexis
    Commented Jan 30, 2013 at 0:50
  • I don't recommend to customize toolbars in Word. There is no temporary parameter like Excel or Powerpoint has. This leeds to a big problem, if you want to remove a toolbar. You can't just delete all code in normal.dot. You always have to manually delete or reset the toolbar.
    – nixda
    Commented Jan 30, 2013 at 8:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .