• If toolbar/macros exist (VBA/Word 97)

    Author
    Topic
    #358425

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #534810

      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

      • #534815

        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 smile

        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.

        • #534817

          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.

        • #534834

          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

          • #534837

            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.

            • #534876

              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.

    Viewing 0 reply threads
    Reply To: If toolbar/macros exist (VBA/Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: