Code to work in any open workbook

Hello,

i got this below code from internet, it works when i put this code in every sheet code page. however what i need is help to modify the code so that by default it works in any opened workbook active sheet, and i do not have to manually paste this code in every window of sheet vba.

thanks

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Cells.Count > 1 Then Exit Sub

Cells.Borders.LineStyle = xlLineStyleNone

ActiveCell.EntireColumn.BorderAround Weight:=xlThick, Color:=RGB(117, 173, 33)

ActiveCell.EntireRow.BorderAround Weight:=xlThick, Color:=RGB(117, 173, 33)

End Sub

Open in new window

LVL 6
FloraAsked:
Who is Participating?
 
gowflowCommented:
or save this file to the following location
C:\Users\<UserName>\AppData\Roaming\Microsoft\Excel\XLSTART

where <UserName> is the user id you log in windows.
and try opening any excel.
gowflow
Personal.xlsb
0
 
gowflowCommented:
put this code in personal.xlsb and save it to your xlstart folder so it will launch it each time you open a workbook. or create an addin with it.

If you need help let me know
gowflow
0
 
FloraAuthor Commented:
gowflow,

did not work. where in personal.xlsb shall i put the above code?  in which sheet?  

my personal xlsb file is hidden, so all of my macros in personal file is visible, but the worksheet change event did not work.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
gowflowCommented:
We just crossed. As you can see the code is in ThisWorkbook SheetSelectionChange Event

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub

Cells.Borders.LineStyle = xlLineStyleNone

ActiveCell.EntireColumn.BorderAround Weight:=xlThick, Color:=RGB(117, 173, 33)

ActiveCell.EntireRow.BorderAround Weight:=xlThick, Color:=RGB(117, 173, 33)


End Sub

Open in new window


gowflow
0
 
FloraAuthor Commented:
now it works.

thanks gowflow
0
 
gowflowCommented:
Welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.