Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington (Greater Manchester area)/Cheshire, UK
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Moving macros around

    I am wanting to copy a macro and some forms from a Word document into Normal.dot. I am also wanting to set a button on the toolbar which is set to run one of the subroutines in the macro I want to copy.

    Is there a way of doing this? Is it fairly easy or complicated?

    Thanks

    James

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

    Re: Moving macros around

    Easy

    Go to the VB Editor, Show the Project Explorer (Ctrl-R) and drag from one template to another to make copies of each module or userform.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Moving macros around

    It is fairly easy.

    Why do you want to copy them into Normal.dot, though? Why not a different global template and avoid putting things in Normal.dot that you don't need there?

    See: <A target="_blank" HREF=http://www.addbalance.com/usersguide/templates.htm>http://www.addbalance.com/usersguide/templates.htm</A> for more information on use and placement of global templates.

    Anyway, if your macros are all in one module (and it has a different name from any module in your target template, you can use the Organizer to copy them. Tools => Templates and Add-Ins... => Organizer (button). It is pretty straightforward. If you are copying toolbars, too, copy the macros first. You can use the Organizer even if the donor or recipient template is not open. The defaults are the current document / template and Normal.dot.

    Otherwise, since you mentioned forms I assume that you are talking about userforms and are familiar with the VBA Editor. You can cut and paste from one project to another easily. Except for Normal.dot, any template or document you are copying to/from has to be open in Word.

    Hope this helps.
    Charles Kyle Kenyon
    Madison, Wisconsin

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington (Greater Manchester area)/Cheshire, UK
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving macros around

    Is there a way to do this with with VBA?

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Moving macros around

    Hi James,

    To use the classifications from your first post, moving these in the manner suggested by Andrew is fairly easy - give it a try!

    Theoretically it's possible to move these things around via code, but you don't want to go there (that's about as complicated as you can get) - why complicate things unnecessarily?[img]/w3timages/icons/wink.gif[/img]

    Gary

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington (Greater Manchester area)/Cheshire, UK
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving macros around

    I would place it in a different file, but we have users who ofetn create ID 10 T errors and we want to keep away any potential probems with this macro.

    Thanks for the suggestion about the site, I seem to be battling to connect to the site at the moment, I'll have a look at it the office tommorrow.

    Do you know how to move macros between the document and other templates using VBA?

    Thanks for the response so far....

    James

  7. #7
    kzytv4
    Guest

    Re: Moving macros around

    Microsoft's KBase article Q189003 has information on copying modules using VBA code - but I keep getting a "Type Mismatch" error on the following line:

    Set ModuleToCopy = _ Application.VBE.ActiveVBProject.VBComponents("modu le2")

    The module name is Module2, the variable has been dimensioned to VBComponent & I've added the Reference to Microsoft Visual Basic for Applications Extensibility (as recommended by the site) - not sure where to go next...

    Thanks!
    Tracey Morris

  8. #8
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Moving macros around

    I would first try recording a macro using the Organizer. Obviously, you want to be copying a module other than the one to which the macro is being recorded (New Macros).
    Charles Kyle Kenyon
    Madison, Wisconsin

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving macros around

    >Theoretically it's possible to move these things around via code, but you don't want to go there (that's about as complicated as you can get)

    Nonsense!

    There's always my little "Function intCopyModules(docSource As Document, docTarget As Document) As Integer" which is described as "For each module in Source that exists in Target, copy it from Source to Target.".

    Great way to update an application with the essential latest from a common library template (grin!).

    Here's the TESTbed:

    <pre>Sub TESTintCopyModules()
    MsgBox "Copies from an open unprotected Utils076.dot to the active document!!!!!"
    MsgBox intCopyModules(Documents("utils076.dot"), ActiveDocument)
    End Sub
    </pre>



    I can't believe I'm doing this JUST to see if I'm getting the hang of posting a reply with embedded code .....

  10. #10
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington (Greater Manchester area)/Cheshire, UK
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Moving macros around

    Thanks - I'll have a look

Posting Permissions

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