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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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
 
Upvote 0
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?
 
Upvote 0
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
 
Upvote 0
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.
 
Upvote 0
Cross-posted (and apparently already resolved) here.
 
Upvote 0
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.
 
Upvote 0
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. :)
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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
Back
Top