Consulting

Results 1 to 3 of 3

Thread: Attaching Macro to object when emailing workbooks

  1. #1
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location

    Lightbulb Attaching Macro to object when emailing workbooks

    I have been struggling with a problem and was unable to find a direct solution in the forum. However some of the posts did point me in the right direction, so I thought I'd post the answer (and hopefully save you the hair-pulling and muttered four-letter words I went through!)

    Problem:
    I have a workbook in which an individual sheet is to be sent to various users. This sheet has a drawing object with a macro attached. The sheet is copied to a new workbook and saved on a network drive, then sent as attachment in Outlook.

    The macro resides on the sheet that is being copied rather than within a module, so the code is copied along with the sheet.
    The macro works fine if you open the saved workbook. However when you open the attachment in Outlook, it redirects the attached macro to the temporary location used for all Outlook attachments, even if you have hard-coded the full path for the macro.
    Solution:
    Make sure that you attach a shortcut to the workbook, rather then embedding the workbook in the email message.


    ' make sure full path to macro is attached to the button
     ' (macro is in current sheet rather than module)
    Worksheets(1).Shapes(1).OnAction = _
     "'" & strAttachPath & "'!shBuyer.SubmitToCapture"
    ...
    With objMail
        .To = strBuyer
        .Subject = "Allocate New Stores/Fixtures Allowance"
        .Attachments.Add strAttachPath, olByReference
        .Send
    End With

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Nice one!

    Hey, if you don't mind, could you make this as a Knowledge Base submission? I think others would find this very useful.

  3. #3
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Hey, girl.
    Do you mind adding your code to the knowledgebase? There's a link on every page here at the forum to KBase.

    Your login is the same as for the forum and, like the forum, you get a cookie so you don't have to keep logging into it. You don't need to login to see existing kb entries, only to add new ones.
    ~Anne Troy

Posting Permissions

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