Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a macro create a new macro?

Status
Not open for further replies.

OscarPCG

Technical User
Aug 12, 2004
15
US
I want to know if it is possible to create a macro "dynamically"? I am working on a project that will create buttons and add them to a "User's Toolbar". I then need each button to perform a similar but separate action. (the attached code should explain.)

The code that I need to generate, if possible is the following code:
Code:
' used with button to call sName and apply the style
Sub uName(sName)
    Selection.Style = ActiveDocument.Styles(sName) 
End Sub

The buttons can be generated with the following code.

Code:
sub uName (sName)
Dim myPop As CommandBarPopup
Dim myBut As CommandBarButton
Dim myToolbarName As String

myToolbarName = "User's Styles"
    Set myPop = CommandBars(myToolbarName).Controls.Add(Type:=msoControlPopup)
    myPop.Caption = sName 

        Set myBut = myPop.Controls.Add(Type:=msoControlButton)
        myBut.Caption = sName
        myBut.FaceId = 59 'smilly
        myBut.OnAction = uName ' macro name
end sub

Thanks
Oscar
 
It is not clear from your post what you actually wish to accomplish.

It seems as if you are trying to distribute a collection of tools. Is this correct?
 
I have a wizard that allows user’s to create and delete custom word styles. I want to create a user's toolbar and add any user created styles to the toolbar (as a button with a link to a macro that will apply the designated formatting style to a selected paragraph).

(In the end I am trying to make Word less usable [bigsmile])
 
u must be serious about making Word less usable as this is bad design.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top