Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Apr 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Word 2010 - creating similar macros for several docs

    I have a Word 2010 macro like the following that has been working fine for a single document for a while. Now I need to create similar macros for two more documents, each with a different path and file name. It's not obvious to me where Word / VBA is saving them and I'm getting crosstalk between the macros as I try to modify them.

    Code:
        ChangeFileOpenDirectory _
            "C:\...\"
        Application.DisplayAlerts = wdAlertsNone
        ActiveDocument.SaveAs2 FileName:="filename.ans", FileFormat:=101, _
             LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
            :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
            SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
            False, CompatibilityMode:=0
        Application.Quit SaveChanges:=wdDoNotSaveChanges
    End Sub

  2. #2
    New Lounger
    Join Date
    Apr 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I can't make sense of what Word 2010 does with macros. Apparently they were being stored in Normal.dotm, which would be fine, except after I tried to edit that file they disappeared completely. I tried creating a filename.dotm file, but if I record a macro and save it, the next time I opened the .dotm file, it's gone. This is particularly confusing since as long as I had just the one macro for the one file it worked fine.

    Is there perhaps a third-party macro utility that's compatible with Word and better behaved?

  3. #3
    New Lounger
    Join Date
    Apr 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It got worse, so that any time I tried to create a macro it fails with the error, "The project item name is not valid."

    Apparently I somehow saved an invalid macro and it was messing things up. I eventually blundered into editing it, deleted it all, and things seem to be working normally again.

    I think my basic problem was not understanding that the macros weren't saved locally to the file, so as I was creating macros with the same name in different files Word / VBA got in an unusable state.

  4. #4
    3 Star Lounger
    Join Date
    Apr 2012
    Posts
    240
    Thanks
    3
    Thanked 24 Times in 24 Posts
    Easiest thing to do is copy the complete original macro, from "Sub" to "End Sub" and paste it directly below the original. The VBA editor should put a line between the two macros. Next, rename the macro by changing the "Sub macroname" (1st line of macro) to "Sub NewMacroname" (your choice) Modify the new macro as required.
    Then on the VBA toolbar, click the Save button (or click File, Save Normal).
    Close the VBA editor and check that the new macro exists (click the developer tab, and select Macros on the left)

    Finally, close and re-open and verify everything's working.

  5. The Following User Says Thank You to BigMac56 For This Useful Post:

    Robert Lauriston (2012-09-25)

  6. #5
    New Lounger
    Join Date
    Apr 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks, I eventually figured that out yesterday. It's strange that three macros should be (apparently) defined as separate subroutines in the same file and that I can no longer save each macro in the only file where it will work, but whatever.

  7. #6
    3 Star Lounger
    Join Date
    Apr 2012
    Posts
    240
    Thanks
    3
    Thanked 24 Times in 24 Posts
    Actually you can save them in the individual files, didnt' think you were looking to do that.
    When you open VBA you should see the Project Explorer in the top left corner below the tool bar. First project should be normal, and each other document you have open should be listed below it. (unnamed documents will be called Project (Document1) or something similar. Click on the project you want to place your macro in and click Insert, Module. It will create Module1, where you can paste your macro to, then modify as required.

  8. #7
    New Lounger
    Join Date
    Dec 2009
    Location
    Melbourne, Australia
    Posts
    22
    Thanks
    3
    Thanked 0 Times in 0 Posts
    When you create a macro in word 2010 you have three options in the Macros in: drop-down box:
    Normal.dotm(global template) stores the macro in the global template, meaning that the macro is available to every document you create from scratch New/Blank document). You should use this option only for macros which are really relevant to all documents. Otherwise your Global template will become unnecessarily cluttered, slowing down the operation of Word.
    All active templates and documents stores the macro in all templates and documents you have open in Word when you create the macro.
    Document1 (document) stores the macro only in document Document1 (or whatever other name you have given to the current document).

    (The other option in the Drop-down list, Word commands, is not relevant to macro storage, but lists all of the built-in commands which you may run but not change. as you highlight each of these you will see a description of what it will do.)

Posting Permissions

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