Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 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

share|improve this answer
    
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 Jan 29 '13 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 Jan 30 '13 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 Jan 30 '13 at 8:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.