View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default How do I Create a Macro to run VB Code in Excel?

We can do this in two steps:

1. transfer the logic from the event macro to a public macro
2. assign the public macro to an icon or shape

Here is an example:

we start with:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox ("Hello World")
End Sub

The first thing to to create a public macro in a standard module:

Public Sub gator()
MsgBox ("hello World")
End Sub

and the old event macro gets modified to:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
call gator
End Sub

At this point any routine can call gator. Insert any picture in the
worksheet; right-click the picture and assign it the sub gator

--
Gary''s Student - gsnu200763


"Gator" wrote:

I have a Private Sub named Worksheet_SelectionChange(ByVal Target As Range)
How do I create a macro to run this code. I am trying to assign VB Code to
run when I click an icon that I made. I get stuck when I have to assign a
macro to the icon. Do I just use the sub name above? Do I create a macro to
run the sub and then assign the icon to the macro?
HELP
--
Gator