Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If toolbar/macros exist (VBA/Word 97)

    I have some code that copies a toolbar, autotext and macros to the existing document. However, if the macros already exist in the document, I get an error message (Runtime 5940 - the project item cannot be copied). I don't know how to check to see if the toolbar, macros and autotext entries already exist in the current document. Here's a portion of the code:

    Sub CopyMacros()
    Dim strThisDocument As String

    strThisDocument = ActiveDocument.FullName
    Application.OrganizerCopy Source:= _
    "C:Program FilesMicrosoft OfficeTemplatesFirm GeneralFirmLtr.dot", _
    Destination:=strThisDocument, Name:="Firm Letter", _
    Object:=wdOrganizerObjectCommandBars
    Application.OrganizerCopy Source:= _
    "C:Program FilesMicrosoft OfficeTemplatesFirm GeneralFirmLtr.dot", _
    Destination:=strThisDocument, Name:="PrintLetter", _
    Object:=wdOrganizerObjectProjectItems
    Application.OrganizerCopy Source:= _
    "C:Program FilesMicrosoft OfficeTemplatesFirm GeneralFirmLtr.dot", _
    Destination:=strThisDocument, Name:="PrintLabel", _
    Object:=wdOrganizerObjectProjectItems
    Application.OrganizerCopy Source:= _
    "C:Program FilesMicrosoft OfficeTemplatesFirm GeneralFirmLtr.dot", _
    Destination:=strThisDocument, Name:="PrintEnvelope", _
    Object:=wdOrganizerObjectProjectItems
    End Sub

    There is also probably a much more streamlined way to effect each copy but I'm quite a novice at this stuff so please bear with me. Thanks for any assistance.

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If toolbar/macros exist (VBA/Word 97)

    Hummm. I can execute similar code in Word 97 and it copies the commandbar everytime even if it already exists. You could try "On error resume next" at the top of your code to see if that helps.

    You could also "improve" your code with a loop if all the FirmLtr commandbars are to be copied. Such as this autotext example:

    Dim aEntry As AutoTextEntry
    For Each aEntry In tProjectFileName.AutoTextEntries ' ActiveDocument.AttachedTemplate.AutoTextEntries
    Application.OrganizerCopy [t Source:=tProjectFileName.FullName, _
    Destination:=ActiveDocument.FullName, Name:=aEntry.Name, _
    Object:=wdOrganizerObjectAutoText
    Next aEntry
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If toolbar/macros exist (VBA/Word 97)

    Hey Kevin!

    Thanks for your reply. I guess the problem I have found is with the all the forms (frmLP, frmEnvelope, etc.) as well as the macros that run the forms (PrintLetter, PrintEnvelope), etc. The commandbar doesn't seem to be the problem. Unfortunately, the macro project items are the offending entities <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    I will try to clean up the code a little -- I also attempted to delete the items first, but if they don't exist, obviously, I get another error message. So I was looking for an If statement that would check to see if they exist and if not, copy it to the new document.

    I'll keep plugging away as this will make work at my firm much easier if I can accomplish it. Take care! Hope all is well with you.

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If toolbar/macros exist (VBA/Word 97)

    Try the

    On error resume next

    if you don't want to see the error message.

    You can check to see if the macro items exist, but you have to get into the VBComponents object. That would seem to be a whole bunch of code you may not really need.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

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

    Re: If toolbar/macros exist (VBA/Word 97)

    Hi Joanne,

    Apropos of making the work easier, I was just wondering: what is the scenario that requires the toolbars, macros etc. to be copied to a document? (since usually they can get these from the attached template).

    Gary

  6. #6
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If toolbar/macros exist (VBA/Word 97)

    Hi Gary,

    This is a document which results from a HotDocs merge. The users are used to having a Print letter, print envelope, print label, edit cc information, etc. toolbar which they invoke for certain functions. However, if I attach our FirmLtr.dot template to the merged HotDocs document, the HotDocs document is missing some variables that the FirmLtr.dot populates.

    What I've ended up doing is copying the FirmLtr.dot, remming out the statements I don't want, and gathering the sender information via an input box. This will suffice I believe -- the users have all the functionality they're used to but without the variable error messages. They simply will have to type in the sender because I can't capture that information from HotDocs (or at least I don't know how to capture it....).

    This is probably very convoluted... my apologies.

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If toolbar/macros exist (VBA/Word 97)

    You could re-design the app so that the document variables are created in the document, not in the template.

    I do not see any need to copy the toolbars. macros, etc, to the document.

Posting Permissions

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