Yes, in vba you have the possibility to create with vba a vba makro by realtime. So you can create a macro. In VBA it goes like this:Can you add a macro to an Excel workbook through COMate?
Code: Select all
ActiveWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule.Lines(1, 1) "'This is a comment"
This looks very complicate to do this with a web gadget but maybe its the only way to do this .... damnAs I say, if you wish to catch some events then I would guess that you'll have to load the worksheet into a web gadget or an instance of IE. You can certainly catch events from an IE instance as I've done this myself.

i found out some interessting thing. Maybe its a bug, but maybe its a new point to fix the problem:
Code: Select all
XIncludeFile "C:\Desktop\COMate_Residents.pbi"
XIncludeFile "C:\Desktop\COMate.pbi"
Global objExcel.COMateObject
objCommandBars.COMateObject
objCommandBarsButton1.COMateObject
Global Quit
Procedure myEventCallback(object.COMateObject, eventName.s, parameterCount)
If eventName.s="Click"
objExcel\Release()
End
EndIf
EndProcedure
objExcel=COMate_GetObject("", "Excel.Application")
If objExcel=0
objExcel=COMate_CreateObject("Excel.Application")
EndIf
If objExcel
If objExcel\SetProperty("Visible = #True") = #S_OK
objExcel\Invoke("CommandBars('Test')\Delete")
objCommandBars=objExcel\GetObjectProperty("CommandBars\Add('Test', 1, 0, 0)") ;1=Position , 0=MenuBar , 0=Temporary
If objCommandBars
objCommandBars\SetProperty("Left = 0")
objCommandBars\SetProperty("Visible = #False")
objCommandBarsButton1=objExcel\GetObjectProperty("CommandBars('Test')\Controls\Add(1)")
If objCommandBarsButton1
objCommandBarsButton1\SetProperty("Style = 11") ; 11=msoButtonIconAndCaptionBelow
objCommandBarsButton1\SetProperty("FaceId = 548")
objCommandBarsButton1\SetProperty("Caption = 'Test'")
objCommandBarsButton1\SetProperty("TooltipText = 'Test'")
objCommandBarsButton1\SetProperty("BeginGroup = #True")
;objCommandBarsButton1\SetProperty("OnAction = 'MyMacro'")
objExcel\SetProperty("CommandBars('Test')\Visible = #True")
HRESULT=objCommandBarsButton1\SetEventHandler(@myEventCallback())
If HRESULT
Else
;Debug "error5"
EndIf
Else
Debug "error3"
EndIf
Else
Debug "error2"
EndIf
Else
Debug "error7"
EndIf
Else
Debug "error1"
EndIf
MessageRequester("","Don't close this msgbox, please try the button!")
objExcel\Release()
Code: Select all
XIncludeFile "C:\Desktop\COMate_Residents.pbi"
XIncludeFile "C:\Desktop\COMate.pbi"
Global objExcel.COMateObject
objCommandBars.COMateObject
objCommandBarsButton1.COMateObject
Global Quit
Procedure myEventCallback(object.COMateObject, eventName.s, parameterCount)
Debug object.COMateObject
If eventName.s="Click"
objExcel\Release()
End
EndIf
EndProcedure
objExcel=COMate_GetObject("", "Excel.Application")
If objExcel=0
objExcel=COMate_CreateObject("Excel.Application")
EndIf
If objExcel
If objExcel\SetProperty("Visible = #True") = #S_OK
objExcel\Invoke("CommandBars('Test')\Delete")
objCommandBars=objExcel\GetObjectProperty("CommandBars\Add('Test', 1, 0, 0)") ;1=Position , 0=MenuBar , 0=Temporary
If objCommandBars
objCommandBars\SetProperty("Left = 0")
objCommandBars\SetProperty("Visible = #False")
objCommandBarsButton1=objExcel\GetObjectProperty("CommandBars('Test')\Controls\Add(1)")
If objCommandBarsButton1
objCommandBarsButton1\SetProperty("Style = 11") ; 11=msoButtonIconAndCaptionBelow
objCommandBarsButton1\SetProperty("FaceId = 548")
objCommandBarsButton1\SetProperty("Caption = 'Test'")
objCommandBarsButton1\SetProperty("TooltipText = 'Test'")
objCommandBarsButton1\SetProperty("BeginGroup = #True")
;objCommandBarsButton1\SetProperty("OnAction = 'MyMacro'")
objExcel\SetProperty("CommandBars('Test')\Visible = #True")
HRESULT=objCommandBarsButton1\SetEventHandler(@myEventCallback())
If HRESULT
Else
;Debug "error5"
EndIf
Else
Debug "error3"
EndIf
Else
Debug "error2"
EndIf
Else
Debug "error7"
EndIf
Else
Debug "error1"
EndIf
Repeat
ForEver
;The same with while and wend:
;
;While A=1
;Wend