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]
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

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
38,775
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
38,775
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
38,775
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,718
Messages
5,833,292
Members
430,203
Latest member
rmlnlo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top