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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.