Set Office Commandbar Properties

Add-in Express™ Support Service
That's what is more important than anything else

Set Office Commandbar Properties
 
Peter Domke




Posts: 21
Joined: 2009-06-28
Hello,

with Office 2003, I will position a commandbar where the user left it the last time. All properties like Height, Top, Left, Position etc. are saved and should be applied to the commandbar the next time Word starts.
Since these properties are read-only in the adxCommandbar element, I'm following a hint in this forum and try to use the CommandbarObj Property instead. However, the following code throws a HRESULT exception.

'-----
Try
Dim cmdBar As Microsoft.Office.Core.CommandBar
cmdBar = CType(adx_cb_NumAssist.CommandBarObj,
Microsoft.Office.Core.CommandBar)
With cmdBar
.Height = CInt(g_objSettingsHandler.SettingGetValue(strCmdBarID, _
"Height"))
.Width = CInt(g_objSettingsHandler.SettingGetValue(strCmdBarID, _
"Width"))
.Left = CInt(g_objSettingsHandler.SettingGetValue(strCmdBarID, _
"Left"))
(... etc. ...)
End With
Marshal.ReleaseComObject(cmdBar)
Catch ex As Exception
g_objErr.HandleError(ex.Message)
End Try
'-----
The error is:
"Beim Aufruf einer COM-Komponente wurde ein HRESULT E_FAIL-Fehler zur?ckgegeben. = On calling a com component a HRESULT error was returned."

Are the properties of the CommandBarObj also read-only?

Kind regards
Peter Domke

Posted 01 Jul, 2009 06:56:08 Top
Peter Domke




Posts: 21
Joined: 2009-06-28
Sorry, posted in the wrong forum, should be in the .NET forum instead. Please move my topic. Thanks, Peter
Posted 01 Jul, 2009 09:18:08 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Peter,

You don't need to release cmdBar in your code.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Jul, 2009 12:14:19 Top
Peter Domke




Posts: 21
Joined: 2009-06-28
Andrej,

excuse me that I didn't precise at which line the error is raised.
It is raised the first time I try to access a property, e.g. "height".
I've tried it with a simple integer as follows:

Dim cmdBar As Microsoft.Office.Core.CommandBar
cmdBar = CType(adx_cb_NumAssist.CommandBarObj,
Microsoft.Office.Core.CommandBar)
With cmdBar
.Height = 30 ===> Raises error

==================================================================
"System.Runtime.InteropServices.COMException (0x80004005): Beim Aufruf einer COM-Komponente wurde ein HRESULT E_FAIL-Fehler zur?ckgegeben.
bei Microsoft.Office.Core.CommandBar.set_Height(Int32 pdy)
bei GOTComAddinWordx2.AddinModule.CmdBar_Position(Int64 lngGetSet, String strCmdBarID) in C:\_Develop\GOTComAddinWordx2\AddinModule.vb:Zeile 911."
===========================================================

Please advise
Thanks
Peter
Posted 01 Jul, 2009 13:07:22 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Peter,

bei GOTComAddinWordx2.AddinModule.CmdBar_Position(Int64 lngGetSet, String strCmdBarID)


Try using Int32 instead of Int64.


Andrei Smolin
Add-in Express Team Leader
Posted 01 Jul, 2009 13:38:47 Top
Peter Domke




Posts: 21
Joined: 2009-06-28
Andrej,

the "Int64 lngGetSet" argument is a parameter which is not used in the procedure as input for the commandbar properties; however, I've tried the following:

cmdBar = CType(adx_cb_NumAssist.CommandBarObj,
Microsoft.Office.Core.CommandBar)
With cmdBar
Dim i As Integer
i = CType("65", Integer)
.Height = i '==> Raises the described error

I'm getting the error on Office 2007 (with the Commandbar for Ribbon enabled), and on Office 2003.
In the Direct Window, I can access some properties, e.g.

?cmdBar.NameLocal
"GOT Nummerierungs-Assistent"
?cmdBar.Enabled
True
?cmdBar.Visible
True
?cmdBar.Controls.Count
12
?adx_cb_NumAssist.UseForRibbon
True
?cmdBar.height
26
?cmdBar.width
200

I can also set the position, e.g.
cmdBar.Position = Microsoft.Office.Core.MsoBarPosition.msoBarBottom

but I cannot set the height:

cmdBar.Height = 55% '==> this raises the error.

Peter


Posted 01 Jul, 2009 18:10:47 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Peter,

cmdBar.Height = 55%


Try cmdBar.Height = 55. Height, Width, Top, and Left are measured in pixels.


Andrei Smolin
Add-in Express Team Leader
Posted 04 Jul, 2009 08:11:10 Top