+ Reply to Thread
Results 1 to 10 of 10

calling an event macro from a different workbook

  1. #1
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    calling an event macro from a different workbook

    Hi,

    I currently have a macro that opens a workbook in a directory then formats it accordingly. My question is, I want to add a Worksheet_SelectionChange function into Sheet1 of that newly opened workbook to highlight the entire row of the selected cell when the user looks at it. How can I call this in the original macro that opened the workbook? The workbook is a report of some sort and the users need to switch to another program for research as they work through the entire report. It would be a nice feature to have the row highlighted to indicate which account is currently being worked on. Thanks in advance!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: calling an event macro from a different workbook

    Hi cwchan220,

    In the original workbook, try code like the following:
    Please Login or Register  to view this content.
    'Book1', 'Sheet1', and 'F9' refer to the Workbook just opened.

    Lewis

  3. #3
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    Re: calling an event macro from a different workbook

    Are you referring to the original workbook that has the macro that opens the workbook from the directory?

    I might not be explaining thoroughly. Right now, I have a Master workbook that stores the macros to open various reports from a folder. (These reports are updated/overwritten from the server daily so I can't store the macro directly in them.) The macro runs when the user clicks on a button in the Master workbook. After the report opens (in a different workbook), I want Sheet1 on the Report workbook to highlight the entire row of the cell when the user selects it. As the user works on the report, they will select another cell to highlight that row and so on. I am able to get my code to work when I put it in after the Report workbook opens but how do I add it into Sheet1 from the original macro in the Master workbook? Hope that clarifies.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: calling an event macro from a different workbook

    make a new class module in the master workbook called sheetevents and add this code
    Please Login or Register  to view this content.
    in your master workbook add a new module with this
    Please Login or Register  to view this content.
    then in your main routine open the workbook and then add
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    Re: calling an event macro from a different workbook

    I am getting a compile error: User-defined type not defined on the new module with "sh as sheethandler" highlighted and the below in red.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: calling an event macro from a different workbook

    typo
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    Re: calling an event macro from a different workbook

    That got rid of the red but still getting the same error with "sh as sheethandler" highlighted

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: calling an event macro from a different workbook

    oops my bad! I said to name the class sheetevents but you need to call it sheethandler or change the code so it uses sheetevents instead of sheethandler

  9. #9
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    Re: calling an event macro from a different workbook

    Worked like a charm! My first Class Module. All your help is very much appreciated!

  10. #10
    Registered User
    Join Date
    05-23-2014
    Posts
    37

    Re: calling an event macro from a different workbook

    I'm not sure if I should create a new thread for this but I noticed if I open a second Report Workbook, the highlighting stops working for the first one. Is there a workaround for this so that the highlighting works for all the reports that are open?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Calling a macro from an event macro. Using nest loops with if statements
    By c0d3crunch3r in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-12-2012, 08:31 AM
  2. Calling Macro on Closing of Workbook
    By Dirigo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-26-2011, 02:57 PM
  3. Calling a Macro From a diffrent workbook
    By tzahi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-20-2011, 03:27 AM
  4. Calling macro in another workbook
    By scabral in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2009, 02:03 PM
  5. Calling Macro From Different Workbook
    By Launchnet in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-23-2008, 07:03 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1