How to Add Macro to Workbook using Excel VBA
Here is a simple procedure to add a macro to the current workbook using VBComponents
Sub Add_Macro_To_ThisWorkbook()
Dim VBP As VBProject
Dim VBM As VBComponent
Dim VBModule As CodeModule
Dim VBProc As VBComponent
Set VBP = ThisWorkbook.VBProject
Set VBModule = VBP.VBComponents.Item("ThisWorkbook").CodeModule
VBModule.AddFromString ("Sub Sample_Macro" & vbCrLf & "ret = msgbox (""Hello VBADUD"") " & vbCrLf & "End Sub")
End Sub
Showing posts with label VBA ThisWorkbook.VBProject. Show all posts
Showing posts with label VBA ThisWorkbook.VBProject. Show all posts
Tuesday, September 30, 2008
Subscribe to:
Posts (Atom)
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.