calling an event macro from a different workbook

cwchan220

New Member
Joined
Jul 30, 2014
Messages
23
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? Thanks in advance!

Code:
[/COLOR]Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
    With Target
        Cells.Interior.ColorIndex = xlColorIndexNone
        .EntireRow.Interior.ColorIndex = 8


    End With
    

End Sub[COLOR=#333333]
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
I wonder whether it is necessary to have an EVENT CODE.
BETTER KEEP THE SECOND WORKBOOK SAFELY SOMEWHERE FOR RETRIEVAL IF SOMETHING GOES WRONG
this macro is in a fresh workbook
Code:
Sub test()
Workbooks.Open "c:\users\systems\desktop\nse bhav data.xlsm"   [B]'CHANGE PATH AND FILE NAME[/B]
With ActiveWorkbook
With Worksheets(1)   [U][B]'CHANGE INDEX OF WORKSHEET[/B][/U]
MsgBox "in first sheeet of active workbook select any cell"
.Cells.Interior.ColorIndex = xlNone
Selection.EntireRow.Cells.Interior.ColorIndex = 8
End With
End With
With ActiveWorkbook
.Save
.Close
End With


End Sub
 

cwchan220

New Member
Joined
Jul 30, 2014
Messages
23
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. I thought it would be a nice feature to have the row highlighted to indicate which account is currently being worked on. Is the event code not suitable for this?
 

venkat1926

Well-known Member
Joined
Aug 21, 2005
Messages
4,824
event code is fired automaticaly as soon as you select. any how you want to call the code from another workbook for which a macro is required and such why not incorporate the coloring code in the macro itself.
of course I am not an expert
 

cwchan220

New Member
Joined
Jul 30, 2014
Messages
23

ADVERTISEMENT

I might not be explaining thoroughly. Right now, I have a Master workbook that stores the macros to open various reports from a [FONT=inherit !important][FONT=inherit !important]folder[/FONT][/FONT]. (These reports are updated/overwritten from the [FONT=inherit !important][FONT=inherit !important]server[/FONT][/FONT] 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 the event code into Sheet1 from the original macro in the Master workbook? Hope that clarifies.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,503
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Cross-posted (and apparently already resolved) here.
 

cwchan220

New Member
Joined
Jul 30, 2014
Messages
23

ADVERTISEMENT

Apologies, didn't realize it's the same site but I had a follow up question so I didn't know if it will require a different solution or a new thread.
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,503
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
It's not the same site. However, if you read the rules on cross-posting at either site, you'll see that you should provide links when you do this. You'll also find a link to an article explaining why you should do this. :)
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,503
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
No problem. :)

I suggest you post the follow-up as a new thread. You can include a link to this thread if it's relevant.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,033
Messages
5,526,371
Members
409,697
Latest member
christopherlewis1620

This Week's Hot Topics

Top