ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Exel2000 VBA - Creating a Command Bar - Error: "Object Variable or With not Set" (https://www.excelbanter.com/excel-programming/274091-re-exel2000-vba-creating-command-bar-error-object-variable-not-set.html)

keepITcool

Exel2000 VBA - Creating a Command Bar - Error: "Object Variable or With not Set"
 

In addition to Tom's remark:

I see a hard return but no line continuation where you add the Button?

Use:

Set btnRun = barTemp.Controls.Add _
(Type:=msoControlButton, temporary:=True)


Also:

Dim btnRun as Office.CommandBarButton

the CommandBarControl is more generic.. if u use CommandBarButton Object
you'll see more properties to work with.


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Tom Ogilvy" wrote:

in the workbook_open event you should prefix with application


Private Sub Workbook_Open()
Dim barTemp As CommandBar
Dim btnRun As CommandBarControl

Set barTemp = Application.CommandBars.Add(Name:="Temp", _
Position:=msoBarFloating, MenuBar:=False, temporary:=True)

Set btnRun = barTemp.Controls.Add
(Type:=msoControlButton, temporary:=True)

End Sub

This usually clears up this type of problem.



All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com