COM AddIn for Word does not store the position properly

  • Thread starter Thread starter Jaime Rios
  • Start date Start date
J

Jaime Rios

Hi,
I created a COM AddIn for Word that performs the functions
that it needs to, but I needed to add the ability for the
toolbar created by the COM AddIn to remember it's last
position and whether it was docked or not. I added the
following code to my "OnConnection" function but it fails
with an error, "Run-time exception thrown :
System.IO.IOException - Bad file name or number."

With applicationObject.CommandBars("SampleToolbar")
.Left = CLng(GetSetting
("SampleToolbar", "General", "ToolbarLeft", 0))
.Top = CLng(GetSetting
("SampleToolbar", "General", "ToolbarTop", 0))
.Position = CLng(GetSetting
("SampleToolbar", "General", "ToolbarPos", CStr
(msoBarTop)))
.Index = CLng(GetSetting
("SampleToolbar", "General", "ToolbarIndex", 0))
End With

Any help is appreciated! Thanks!

Jaime Rios
 
Hi Jaime,

You may try to check if the Registry setting has been set. [using the
regedit tool]
The setting is usually under the Key
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
and
HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Software\VB and
VBA Program Settings\AppTest
the <> section may be different from yours. You may search using the find
function in the regedit.

I suggest that you break the with-endwith section into four code line to
see which function cause the error.
Since it seems the error you got is related with the File System, do you
have any file system operation?

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
 
Now I am having a problem where the COM AddIn will not load at all! Is there
a setting or something that Word has done to prevent it from loading?

Jaime
Peter Huang said:
Hi Jaime,

You may try to check if the Registry setting has been set. [using the
regedit tool]
The setting is usually under the Key
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
and
HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Software\VB and
VBA Program Settings\AppTest
the <> section may be different from yours. You may search using the find
function in the regedit.

I suggest that you break the with-endwith section into four code line to
see which function cause the error.
Since it seems the error you got is related with the File System, do you
have any file system operation?

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jaime Rios" <[email protected]>
Sender: "Jaime Rios" <[email protected]>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOBCrvTw0D7D7R6RiqyWJZyUpmpvA==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109406
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,
I created a COM AddIn for Word that performs the functions
that it needs to, but I needed to add the ability for the
toolbar created by the COM AddIn to remember it's last
position and whether it was docked or not. I added the
following code to my "OnConnection" function but it fails
with an error, "Run-time exception thrown :
System.IO.IOException - Bad file name or number."

With applicationObject.CommandBars("SampleToolbar")
.Left = CLng(GetSetting
("SampleToolbar", "General", "ToolbarLeft", 0))
.Top = CLng(GetSetting
("SampleToolbar", "General", "ToolbarTop", 0))
.Position = CLng(GetSetting
("SampleToolbar", "General", "ToolbarPos", CStr
(msoBarTop)))
.Index = CLng(GetSetting
("SampleToolbar", "General", "ToolbarIndex", 0))
End With

Any help is appreciated! Thanks!

Jaime Rios
 
Figured this one out, the COM AddIn was disabled under the disabled items
button in the Help->About Word dialog box. But I am still having problems
setting the toolbar position. Here is the code, but it keeps giving me the
error:

Error of type: 458 has occurred.
Desc: Bad variable type
When I try to set the position properties! Any ideas? Thanks in advance!

Dim lToolbarPos As Long
Dim lToolbarIndex As Long
Dim lToolbarTop As Long
Dim lToolbarLeft As Long

' Get the toolbar position
lToolbarPos = CLng(GetSetting("SampleToolbar", "General",
"ToolbarPos", CStr(msoBarTop)))
lToolbarIndex = CLng(GetSetting("SampleToolbar", "General",
"ToolbarIndex", 0))
lToolbarLeft = CLng(GetSetting("SampleToolbar", "General",
"ToolbarLeft", 100))
lToolbarTop = CLng(GetSetting("SampleToolbar", "General",
"ToolbarTop", 100))

With applicationObject.CommandBars("Sample Toolbar")
If lToolbarPos = msoBarTop Or lToolbarPos = msoBarBottom Or
_
lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight Then
' Set the leftmost position of the toolbar.
If lToolbarLeft < 0 Then
.Left = 100
Else
.Top = lToolbarTop
.Left = lToolbarLeft
End If
' Place the toolbar in the correct row.
If lToolbarIndex < 0 Then
.RowIndex = 1
Else
.RowIndex = lToolbarIndex
End If
End If
End With

Jaime Rios

Jaime Rios said:
Now I am having a problem where the COM AddIn will not load at all! Is there
a setting or something that Word has done to prevent it from loading?

Jaime
Peter Huang said:
Hi Jaime,

You may try to check if the Registry setting has been set. [using the
regedit tool]
The setting is usually under the Key
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
and
HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Software\VB and
VBA Program Settings\AppTest
the <> section may be different from yours. You may search using the find
function in the regedit.

I suggest that you break the with-endwith section into four code line to
see which function cause the error.
Since it seems the error you got is related with the File System, do you
have any file system operation?

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jaime Rios" <[email protected]>
Sender: "Jaime Rios" <[email protected]>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOBCrvTw0D7D7R6RiqyWJZyUpmpvA==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109406
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,
I created a COM AddIn for Word that performs the functions
that it needs to, but I needed to add the ability for the
toolbar created by the COM AddIn to remember it's last
position and whether it was docked or not. I added the
following code to my "OnConnection" function but it fails
with an error, "Run-time exception thrown :
System.IO.IOException - Bad file name or number."

With applicationObject.CommandBars("SampleToolbar")
.Left = CLng(GetSetting
("SampleToolbar", "General", "ToolbarLeft", 0))
.Top = CLng(GetSetting
("SampleToolbar", "General", "ToolbarTop", 0))
.Position = CLng(GetSetting
("SampleToolbar", "General", "ToolbarPos", CStr
(msoBarTop)))
.Index = CLng(GetSetting
("SampleToolbar", "General", "ToolbarIndex", 0))
End With

Any help is appreciated! Thanks!

Jaime Rios
 
Hi Jaime,

I can not reproduce the problem.
Can you tell me which code line the error occurred?
Here is my test code.
Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
Dim MyButton As Office.CommandBarButton
Dim wdApp As Word.Application
Dim oCmdBars As Office.CommandBars
Dim oCmdBar As Office.CommandBar
wdApp = New Word.ApplicationClass
wdApp.Documents.Add()
wdApp.Visible = True
oCmdBars = wdApp.CommandBars
oCmdBar = wdApp.CommandBars.Add("My CommandBar",
Office.MsoBarPosition.msoBarBottom, False, True)
oCmdBars("My CommandBar").Visible = True
oCmdBar.Left = 100
oCmdBar.RowIndex = 3
MyButton =
oCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)
MyButton.Caption = "My Custom Button"
MyButton.Style = Office.MsoButtonStyle.msoButtonCaption
wdApp.ActiveDocument.Saved = True
wdApp.Quit()
wdApp = Nothing
End Sub
End Module

To debug the code in the command application,e.g. a console application or
a windows application first.
This will accelerate identifying the problem.
I look forward to hearing from you.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Tue, 23 Sep 2003 11:33:41 -0400
Lines: 136
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109595
X-Tomcat-NG: microsoft.public.dotnet.general

Figured this one out, the COM AddIn was disabled under the disabled items
button in the Help->About Word dialog box. But I am still having problems
setting the toolbar position. Here is the code, but it keeps giving me the
error:

Error of type: 458 has occurred.
Desc: Bad variable type
When I try to set the position properties! Any ideas? Thanks in advance!

Dim lToolbarPos As Long
Dim lToolbarIndex As Long
Dim lToolbarTop As Long
Dim lToolbarLeft As Long

' Get the toolbar position
lToolbarPos = CLng(GetSetting("SampleToolbar", "General",
"ToolbarPos", CStr(msoBarTop)))
lToolbarIndex = CLng(GetSetting("SampleToolbar", "General",
"ToolbarIndex", 0))
lToolbarLeft = CLng(GetSetting("SampleToolbar", "General",
"ToolbarLeft", 100))
lToolbarTop = CLng(GetSetting("SampleToolbar", "General",
"ToolbarTop", 100))

With applicationObject.CommandBars("Sample Toolbar")
If lToolbarPos = msoBarTop Or lToolbarPos = msoBarBottom Or
_
lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight Then
' Set the leftmost position of the toolbar.
If lToolbarLeft < 0 Then
.Left = 100
Else
.Top = lToolbarTop
.Left = lToolbarLeft
End If
' Place the toolbar in the correct row.
If lToolbarIndex < 0 Then
.RowIndex = 1
Else
.RowIndex = lToolbarIndex
End If
End If
End With

Jaime Rios

Jaime Rios said:
Now I am having a problem where the COM AddIn will not load at all! Is there
a setting or something that Word has done to prevent it from loading?

Jaime
Peter Huang said:
Hi Jaime,

You may try to check if the Registry setting has been set. [using the
regedit tool]
The setting is usually under the Key
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
and
HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Software\VB and
VBA Program Settings\AppTest
the <> section may be different from yours. You may search using the find
function in the regedit.

I suggest that you break the with-endwith section into four code line to
see which function cause the error.
Since it seems the error you got is related with the File System, do you
have any file system operation?

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jaime Rios" <[email protected]>
Sender: "Jaime Rios" <[email protected]>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOBCrvTw0D7D7R6RiqyWJZyUpmpvA==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109406
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,
I created a COM AddIn for Word that performs the functions
that it needs to, but I needed to add the ability for the
toolbar created by the COM AddIn to remember it's last
position and whether it was docked or not. I added the
following code to my "OnConnection" function but it fails
with an error, "Run-time exception thrown :
System.IO.IOException - Bad file name or number."

With applicationObject.CommandBars("SampleToolbar")
.Left = CLng(GetSetting
("SampleToolbar", "General", "ToolbarLeft", 0))
.Top = CLng(GetSetting
("SampleToolbar", "General", "ToolbarTop", 0))
.Position = CLng(GetSetting
("SampleToolbar", "General", "ToolbarPos", CStr
(msoBarTop)))
.Index = CLng(GetSetting
("SampleToolbar", "General", "ToolbarIndex", 0))
End With

Any help is appreciated! Thanks!

Jaime Rios
 
If you look at my sample that I posted, the line where I try to set the
position with variables, which get their values from the registry, this is
where I am getting the problem;

..Top = lToolbarTop
..Left = lToolbarLeft

As soon as I try to set the first property with the variable, I get the
error. I actually step through the code and see that the variables contain
numerical values that are valid, but the code fails when trying to set the
property. Am I supposed to be doing some sort of typecasting?

Jaime Rios
Peter Huang said:
Hi Jaime,

I can not reproduce the problem.
Can you tell me which code line the error occurred?
Here is my test code.
Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
Dim MyButton As Office.CommandBarButton
Dim wdApp As Word.Application
Dim oCmdBars As Office.CommandBars
Dim oCmdBar As Office.CommandBar
wdApp = New Word.ApplicationClass
wdApp.Documents.Add()
wdApp.Visible = True
oCmdBars = wdApp.CommandBars
oCmdBar = wdApp.CommandBars.Add("My CommandBar",
Office.MsoBarPosition.msoBarBottom, False, True)
oCmdBars("My CommandBar").Visible = True
oCmdBar.Left = 100
oCmdBar.RowIndex = 3
MyButton =
oCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)
MyButton.Caption = "My Custom Button"
MyButton.Style = Office.MsoButtonStyle.msoButtonCaption
wdApp.ActiveDocument.Saved = True
wdApp.Quit()
wdApp = Nothing
End Sub
End Module

To debug the code in the command application,e.g. a console application or
a windows application first.
This will accelerate identifying the problem.
I look forward to hearing from you.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Tue, 23 Sep 2003 11:33:41 -0400
Lines: 136
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109595
X-Tomcat-NG: microsoft.public.dotnet.general

Figured this one out, the COM AddIn was disabled under the disabled items
button in the Help->About Word dialog box. But I am still having problems
setting the toolbar position. Here is the code, but it keeps giving me the
error:

Error of type: 458 has occurred.
Desc: Bad variable type
When I try to set the position properties! Any ideas? Thanks in advance!

Dim lToolbarPos As Long
Dim lToolbarIndex As Long
Dim lToolbarTop As Long
Dim lToolbarLeft As Long

' Get the toolbar position
lToolbarPos = CLng(GetSetting("SampleToolbar", "General",
"ToolbarPos", CStr(msoBarTop)))
lToolbarIndex = CLng(GetSetting("SampleToolbar", "General",
"ToolbarIndex", 0))
lToolbarLeft = CLng(GetSetting("SampleToolbar", "General",
"ToolbarLeft", 100))
lToolbarTop = CLng(GetSetting("SampleToolbar", "General",
"ToolbarTop", 100))

With applicationObject.CommandBars("Sample Toolbar")
If lToolbarPos = msoBarTop Or lToolbarPos = msoBarBottom Or
_
lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight Then
' Set the leftmost position of the toolbar.
If lToolbarLeft < 0 Then
.Left = 100
Else
.Top = lToolbarTop
.Left = lToolbarLeft
End If
' Place the toolbar in the correct row.
If lToolbarIndex < 0 Then
.RowIndex = 1
Else
.RowIndex = lToolbarIndex
End If
End If
End With

Jaime Rios

Jaime Rios said:
Now I am having a problem where the COM AddIn will not load at all! Is there
a setting or something that Word has done to prevent it from loading?

Jaime
Hi Jaime,

You may try to check if the Registry setting has been set. [using the
regedit tool]
The setting is usually under the Key
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
and
HKEY_USERS\ said:
and
VBA Program Settings\AppTest
the <> section may be different from yours. You may search using the find
function in the regedit.

I suggest that you break the with-endwith section into four code line to
see which function cause the error.
Since it seems the error you got is related with the File System, do you
have any file system operation?

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jaime Rios" <[email protected]>
Sender: "Jaime Rios" <[email protected]>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOBCrvTw0D7D7R6RiqyWJZyUpmpvA==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109406
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,
I created a COM AddIn for Word that performs the functions
that it needs to, but I needed to add the ability for the
toolbar created by the COM AddIn to remember it's last
position and whether it was docked or not. I added the
following code to my "OnConnection" function but it fails
with an error, "Run-time exception thrown :
System.IO.IOException - Bad file name or number."

With applicationObject.CommandBars("SampleToolbar")
.Left = CLng(GetSetting
("SampleToolbar", "General", "ToolbarLeft", 0))
.Top = CLng(GetSetting
("SampleToolbar", "General", "ToolbarTop", 0))
.Position = CLng(GetSetting
("SampleToolbar", "General", "ToolbarPos", CStr
(msoBarTop)))
.Index = CLng(GetSetting
("SampleToolbar", "General", "ToolbarIndex", 0))
End With

Any help is appreciated! Thanks!

Jaime Rios
 
Hi Jaime,

The Long Data Type in .NET is 64bit.
Long variables are stored as signed 64-bit (8-byte) integers ranging in
value from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/
vadatlong.asp

While the
The Top Property need Integer which may cause the problem.
You may check it in the Object View by high light the Top in the source
code and Press F12.
You will see as below.
Public Overridable Property Top() As Integer
Member of: Microsoft.Office.Core.CommandBar

Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
SaveSetting("SampleToolbar", "General", "ToolbarPos", 100)
Dim MyButton As Office.CommandBarButton
Dim wdApp As Word.Application
Dim oCmdBars As Office.CommandBars
Dim oCmdBar As Office.CommandBar
wdApp = New Word.ApplicationClass
wdApp.Documents.Add()
wdApp.Visible = True
oCmdBars = wdApp.CommandBars
oCmdBar = wdApp.CommandBars.Add("My CommandBar",
Office.MsoBarPosition.msoBarBottom, False, True)
oCmdBars("My CommandBar").Visible = True
oCmdBar.Left = 100
oCmdBar.RowIndex = 3
Dim tp As Integer = GetSetting("SampleToolbar", "General",
"ToolbarPos")
oCmdBar.Top = tp
MyButton =
oCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)
MyButton.Caption = "My Custom Button"
MyButton.Style = Office.MsoButtonStyle.msoButtonCaption
wdApp.ActiveDocument.Saved = True
wdApp.Quit()
wdApp = Nothing
End Sub
End Module

If this did not resolve the problem,
I really hope you can test my code on your machine, this will help me
isolate the problem.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Wed, 24 Sep 2003 09:13:13 -0400
Lines: 224
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109734
X-Tomcat-NG: microsoft.public.dotnet.general

If you look at my sample that I posted, the line where I try to set the
position with variables, which get their values from the registry, this is
where I am getting the problem;

.Top = lToolbarTop
.Left = lToolbarLeft

As soon as I try to set the first property with the variable, I get the
error. I actually step through the code and see that the variables contain
numerical values that are valid, but the code fails when trying to set the
property. Am I supposed to be doing some sort of typecasting?

Jaime Rios
Peter Huang said:
Hi Jaime,

I can not reproduce the problem.
Can you tell me which code line the error occurred?
Here is my test code.
Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
Dim MyButton As Office.CommandBarButton
Dim wdApp As Word.Application
Dim oCmdBars As Office.CommandBars
Dim oCmdBar As Office.CommandBar
wdApp = New Word.ApplicationClass
wdApp.Documents.Add()
wdApp.Visible = True
oCmdBars = wdApp.CommandBars
oCmdBar = wdApp.CommandBars.Add("My CommandBar",
Office.MsoBarPosition.msoBarBottom, False, True)
oCmdBars("My CommandBar").Visible = True
oCmdBar.Left = 100
oCmdBar.RowIndex = 3
MyButton =
oCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)
MyButton.Caption = "My Custom Button"
MyButton.Style = Office.MsoButtonStyle.msoButtonCaption
wdApp.ActiveDocument.Saved = True
wdApp.Quit()
wdApp = Nothing
End Sub
End Module

To debug the code in the command application,e.g. a console application or
a windows application first.
This will accelerate identifying the problem.
I look forward to hearing from you.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Tue, 23 Sep 2003 11:33:41 -0400
Lines: 136
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109595
X-Tomcat-NG: microsoft.public.dotnet.general

Figured this one out, the COM AddIn was disabled under the disabled items
button in the Help->About Word dialog box. But I am still having problems
setting the toolbar position. Here is the code, but it keeps giving me the
error:

Error of type: 458 has occurred.
Desc: Bad variable type
When I try to set the position properties! Any ideas? Thanks in advance!

Dim lToolbarPos As Long
Dim lToolbarIndex As Long
Dim lToolbarTop As Long
Dim lToolbarLeft As Long

' Get the toolbar position
lToolbarPos = CLng(GetSetting("SampleToolbar", "General",
"ToolbarPos", CStr(msoBarTop)))
lToolbarIndex = CLng(GetSetting("SampleToolbar", "General",
"ToolbarIndex", 0))
lToolbarLeft = CLng(GetSetting("SampleToolbar", "General",
"ToolbarLeft", 100))
lToolbarTop = CLng(GetSetting("SampleToolbar", "General",
"ToolbarTop", 100))

With applicationObject.CommandBars("Sample Toolbar")
If lToolbarPos = msoBarTop Or lToolbarPos = msoBarBottom Or
_
lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight Then
' Set the leftmost position of the toolbar.
If lToolbarLeft < 0 Then
.Left = 100
Else
.Top = lToolbarTop
.Left = lToolbarLeft
End If
' Place the toolbar in the correct row.
If lToolbarIndex < 0 Then
.RowIndex = 1
Else
.RowIndex = lToolbarIndex
End If
End If
End With

Jaime Rios

Now I am having a problem where the COM AddIn will not load at all! Is
there
a setting or something that Word has done to prevent it from loading?

Jaime
Hi Jaime,

You may try to check if the Registry setting has been set. [using the
regedit tool]
The setting is usually under the Key
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
and
HKEY_USERS\ said:
and
VBA Program Settings\AppTest
the <> section may be different from yours. You may search using the
find
function in the regedit.

I suggest that you break the with-endwith section into four code
line
to
see which function cause the error.
Since it seems the error you got is related with the File System, do you
have any file system operation?

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jaime Rios" <[email protected]>
Sender: "Jaime Rios" <[email protected]>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOBCrvTw0D7D7R6RiqyWJZyUpmpvA==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109406
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,
I created a COM AddIn for Word that performs the functions
that it needs to, but I needed to add the ability for the
toolbar created by the COM AddIn to remember it's last
position and whether it was docked or not. I added the
following code to my "OnConnection" function but it fails
with an error, "Run-time exception thrown :
System.IO.IOException - Bad file name or number."

With applicationObject.CommandBars("SampleToolbar")
.Left = CLng(GetSetting
("SampleToolbar", "General", "ToolbarLeft", 0))
.Top = CLng(GetSetting
("SampleToolbar", "General", "ToolbarTop", 0))
.Position = CLng(GetSetting
("SampleToolbar", "General", "ToolbarPos", CStr
(msoBarTop)))
.Index = CLng(GetSetting
("SampleToolbar", "General", "ToolbarIndex", 0))
End With

Any help is appreciated! Thanks!

Jaime Rios
 
Actually that was the problem. Before I got your response back, I started
debugging the application and when I moved the mouse over the property, it
showed the data type as being "Interger". Once I changed the variables from
Long to Interger, everything worked out. Thanks for following up on the
case.

Jaime Rios
Peter Huang said:
Hi Jaime,

The Long Data Type in .NET is 64bit.
Long variables are stored as signed 64-bit (8-byte) integers ranging in
value from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/
vadatlong.asp

While the
The Top Property need Integer which may cause the problem.
You may check it in the Object View by high light the Top in the source
code and Press F12.
You will see as below.
Public Overridable Property Top() As Integer
Member of: Microsoft.Office.Core.CommandBar

Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
SaveSetting("SampleToolbar", "General", "ToolbarPos", 100)
Dim MyButton As Office.CommandBarButton
Dim wdApp As Word.Application
Dim oCmdBars As Office.CommandBars
Dim oCmdBar As Office.CommandBar
wdApp = New Word.ApplicationClass
wdApp.Documents.Add()
wdApp.Visible = True
oCmdBars = wdApp.CommandBars
oCmdBar = wdApp.CommandBars.Add("My CommandBar",
Office.MsoBarPosition.msoBarBottom, False, True)
oCmdBars("My CommandBar").Visible = True
oCmdBar.Left = 100
oCmdBar.RowIndex = 3
Dim tp As Integer = GetSetting("SampleToolbar", "General",
"ToolbarPos")
oCmdBar.Top = tp
MyButton =
oCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)
MyButton.Caption = "My Custom Button"
MyButton.Style = Office.MsoButtonStyle.msoButtonCaption
wdApp.ActiveDocument.Saved = True
wdApp.Quit()
wdApp = Nothing
End Sub
End Module

If this did not resolve the problem,
I really hope you can test my code on your machine, this will help me
isolate the problem.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Wed, 24 Sep 2003 09:13:13 -0400
Lines: 224
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109734
X-Tomcat-NG: microsoft.public.dotnet.general

If you look at my sample that I posted, the line where I try to set the
position with variables, which get their values from the registry, this is
where I am getting the problem;

.Top = lToolbarTop
.Left = lToolbarLeft

As soon as I try to set the first property with the variable, I get the
error. I actually step through the code and see that the variables contain
numerical values that are valid, but the code fails when trying to set the
property. Am I supposed to be doing some sort of typecasting?

Jaime Rios
Peter Huang said:
Hi Jaime,

I can not reproduce the problem.
Can you tell me which code line the error occurred?
Here is my test code.
Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
Dim MyButton As Office.CommandBarButton
Dim wdApp As Word.Application
Dim oCmdBars As Office.CommandBars
Dim oCmdBar As Office.CommandBar
wdApp = New Word.ApplicationClass
wdApp.Documents.Add()
wdApp.Visible = True
oCmdBars = wdApp.CommandBars
oCmdBar = wdApp.CommandBars.Add("My CommandBar",
Office.MsoBarPosition.msoBarBottom, False, True)
oCmdBars("My CommandBar").Visible = True
oCmdBar.Left = 100
oCmdBar.RowIndex = 3
MyButton =
oCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)
MyButton.Caption = "My Custom Button"
MyButton.Style = Office.MsoButtonStyle.msoButtonCaption
wdApp.ActiveDocument.Saved = True
wdApp.Quit()
wdApp = Nothing
End Sub
End Module

To debug the code in the command application,e.g. a console application or
a windows application first.
This will accelerate identifying the problem.
I look forward to hearing from you.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Tue, 23 Sep 2003 11:33:41 -0400
Lines: 136
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109595
X-Tomcat-NG: microsoft.public.dotnet.general

Figured this one out, the COM AddIn was disabled under the disabled items
button in the Help->About Word dialog box. But I am still having problems
setting the toolbar position. Here is the code, but it keeps giving me the
error:

Error of type: 458 has occurred.
Desc: Bad variable type
When I try to set the position properties! Any ideas? Thanks in advance!

Dim lToolbarPos As Long
Dim lToolbarIndex As Long
Dim lToolbarTop As Long
Dim lToolbarLeft As Long

' Get the toolbar position
lToolbarPos = CLng(GetSetting("SampleToolbar", "General",
"ToolbarPos", CStr(msoBarTop)))
lToolbarIndex = CLng(GetSetting("SampleToolbar", "General",
"ToolbarIndex", 0))
lToolbarLeft = CLng(GetSetting("SampleToolbar", "General",
"ToolbarLeft", 100))
lToolbarTop = CLng(GetSetting("SampleToolbar", "General",
"ToolbarTop", 100))

With applicationObject.CommandBars("Sample Toolbar")
If lToolbarPos = msoBarTop Or lToolbarPos =
msoBarBottom
Or
_
lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight Then
' Set the leftmost position of the toolbar.
If lToolbarLeft < 0 Then
.Left = 100
Else
.Top = lToolbarTop
.Left = lToolbarLeft
End If
' Place the toolbar in the correct row.
If lToolbarIndex < 0 Then
.RowIndex = 1
Else
.RowIndex = lToolbarIndex
End If
End If
End With

Jaime Rios

Now I am having a problem where the COM AddIn will not load at all! Is
there
a setting or something that Word has done to prevent it from loading?

Jaime
Hi Jaime,

You may try to check if the Registry setting has been set. [using the
regedit tool]
The setting is usually under the Key
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
and
HKEY_USERS\ said:
and
VBA Program Settings\AppTest
the <> section may be different from yours. You may search using the
find
function in the regedit.

I suggest that you break the with-endwith section into four code line
to
see which function cause the error.
Since it seems the error you got is related with the File System, do
you
have any file system operation?

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jaime Rios" <[email protected]>
Sender: "Jaime Rios" <[email protected]>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOBCrvTw0D7D7R6RiqyWJZyUpmpvA==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109406
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,
I created a COM AddIn for Word that performs the functions
that it needs to, but I needed to add the ability for the
toolbar created by the COM AddIn to remember it's last
position and whether it was docked or not. I added the
following code to my "OnConnection" function but it fails
with an error, "Run-time exception thrown :
System.IO.IOException - Bad file name or number."

With applicationObject.CommandBars("SampleToolbar")
.Left = CLng(GetSetting
("SampleToolbar", "General", "ToolbarLeft", 0))
.Top = CLng(GetSetting
("SampleToolbar", "General", "ToolbarTop", 0))
.Position = CLng(GetSetting
("SampleToolbar", "General", "ToolbarPos", CStr
(msoBarTop)))
.Index = CLng(GetSetting
("SampleToolbar", "General", "ToolbarIndex", 0))
End With

Any help is appreciated! Thanks!

Jaime Rios
 
Hi Jaime,

I am glad that the problem has been resolved.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<#[email protected]>
<[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Thu, 25 Sep 2003 14:12:15 -0400
Lines: 334
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109906
X-Tomcat-NG: microsoft.public.dotnet.general

Actually that was the problem. Before I got your response back, I started
debugging the application and when I moved the mouse over the property, it
showed the data type as being "Interger". Once I changed the variables from
Long to Interger, everything worked out. Thanks for following up on the
case.

Jaime Rios
Peter Huang said:
Hi Jaime,

The Long Data Type in .NET is 64bit.
Long variables are stored as signed 64-bit (8-byte) integers ranging in
value from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html
/
vadatlong.asp

While the
The Top Property need Integer which may cause the problem.
You may check it in the Object View by high light the Top in the source
code and Press F12.
You will see as below.
Public Overridable Property Top() As Integer
Member of: Microsoft.Office.Core.CommandBar

Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
SaveSetting("SampleToolbar", "General", "ToolbarPos", 100)
Dim MyButton As Office.CommandBarButton
Dim wdApp As Word.Application
Dim oCmdBars As Office.CommandBars
Dim oCmdBar As Office.CommandBar
wdApp = New Word.ApplicationClass
wdApp.Documents.Add()
wdApp.Visible = True
oCmdBars = wdApp.CommandBars
oCmdBar = wdApp.CommandBars.Add("My CommandBar",
Office.MsoBarPosition.msoBarBottom, False, True)
oCmdBars("My CommandBar").Visible = True
oCmdBar.Left = 100
oCmdBar.RowIndex = 3
Dim tp As Integer = GetSetting("SampleToolbar", "General",
"ToolbarPos")
oCmdBar.Top = tp
MyButton =
oCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)
MyButton.Caption = "My Custom Button"
MyButton.Style = Office.MsoButtonStyle.msoButtonCaption
wdApp.ActiveDocument.Saved = True
wdApp.Quit()
wdApp = Nothing
End Sub
End Module

If this did not resolve the problem,
I really hope you can test my code on your machine, this will help me
isolate the problem.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Wed, 24 Sep 2003 09:13:13 -0400
Lines: 224
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109734
X-Tomcat-NG: microsoft.public.dotnet.general

If you look at my sample that I posted, the line where I try to set the
position with variables, which get their values from the registry, this is
where I am getting the problem;

.Top = lToolbarTop
.Left = lToolbarLeft

As soon as I try to set the first property with the variable, I get the
error. I actually step through the code and see that the variables contain
numerical values that are valid, but the code fails when trying to set the
property. Am I supposed to be doing some sort of typecasting?

Jaime Rios
Hi Jaime,

I can not reproduce the problem.
Can you tell me which code line the error occurred?
Here is my test code.
Imports Word = Microsoft.Office.Interop.Word
Imports Office = Microsoft.Office.Core
Module Module1
Sub Main()
Dim MyButton As Office.CommandBarButton
Dim wdApp As Word.Application
Dim oCmdBars As Office.CommandBars
Dim oCmdBar As Office.CommandBar
wdApp = New Word.ApplicationClass
wdApp.Documents.Add()
wdApp.Visible = True
oCmdBars = wdApp.CommandBars
oCmdBar = wdApp.CommandBars.Add("My CommandBar",
Office.MsoBarPosition.msoBarBottom, False, True)
oCmdBars("My CommandBar").Visible = True
oCmdBar.Left = 100
oCmdBar.RowIndex = 3
MyButton =
oCmdBar.Controls.Add(Office.MsoControlType.msoControlButton)
MyButton.Caption = "My Custom Button"
MyButton.Style = Office.MsoButtonStyle.msoButtonCaption
wdApp.ActiveDocument.Saved = True
wdApp.Quit()
wdApp = Nothing
End Sub
End Module

To debug the code in the command application,e.g. a console
application
or
a windows application first.
This will accelerate identifying the problem.
I look forward to hearing from you.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
From: "Jaime Rios" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: COM AddIn for Word does not store the position properly
Date: Tue, 23 Sep 2003 11:33:41 -0400
Lines: 136
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109595
X-Tomcat-NG: microsoft.public.dotnet.general

Figured this one out, the COM AddIn was disabled under the disabled items
button in the Help->About Word dialog box. But I am still having problems
setting the toolbar position. Here is the code, but it keeps giving me
the
error:

Error of type: 458 has occurred.
Desc: Bad variable type
When I try to set the position properties! Any ideas? Thanks in advance!

Dim lToolbarPos As Long
Dim lToolbarIndex As Long
Dim lToolbarTop As Long
Dim lToolbarLeft As Long

' Get the toolbar position
lToolbarPos = CLng(GetSetting("SampleToolbar", "General",
"ToolbarPos", CStr(msoBarTop)))
lToolbarIndex = CLng(GetSetting("SampleToolbar", "General",
"ToolbarIndex", 0))
lToolbarLeft = CLng(GetSetting("SampleToolbar", "General",
"ToolbarLeft", 100))
lToolbarTop = CLng(GetSetting("SampleToolbar", "General",
"ToolbarTop", 100))

With applicationObject.CommandBars("Sample Toolbar")
If lToolbarPos = msoBarTop Or lToolbarPos = msoBarBottom
Or
_
lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight
Then
' Set the leftmost position of the toolbar.
If lToolbarLeft < 0 Then
.Left = 100
Else
.Top = lToolbarTop
.Left = lToolbarLeft
End If
' Place the toolbar in the correct row.
If lToolbarIndex < 0 Then
.RowIndex = 1
Else
.RowIndex = lToolbarIndex
End If
End If
End With

Jaime Rios

Now I am having a problem where the COM AddIn will not load at all! Is
there
a setting or something that Word has done to prevent it from loading?

Jaime
Hi Jaime,

You may try to check if the Registry setting has been set. [using the
regedit tool]
The setting is usually under the Key
HKEY_CURRENT_USER\Software\VB and VBA Program Settings
and

HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Software\VB
and
VBA Program Settings\AppTest
the <> section may be different from yours. You may search using the
find
function in the regedit.

I suggest that you break the with-endwith section into four code line
to
see which function cause the error.
Since it seems the error you got is related with the File System, do
you
have any file system operation?

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.

--------------------
Content-Class: urn:content-classes:message
From: "Jaime Rios" <[email protected]>
Sender: "Jaime Rios" <[email protected]>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcOBCrvTw0D7D7R6RiqyWJZyUpmpvA==
Newsgroups: microsoft.public.dotnet.general
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:109406
NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
X-Tomcat-NG: microsoft.public.dotnet.general

Hi,
I created a COM AddIn for Word that performs the functions
that it needs to, but I needed to add the ability for the
toolbar created by the COM AddIn to remember it's last
position and whether it was docked or not. I added the
following code to my "OnConnection" function but it fails
with an error, "Run-time exception thrown :
System.IO.IOException - Bad file name or number."

With applicationObject.CommandBars("SampleToolbar")
.Left = CLng(GetSetting
("SampleToolbar", "General", "ToolbarLeft", 0))
.Top = CLng(GetSetting
("SampleToolbar", "General", "ToolbarTop", 0))
.Position = CLng(GetSetting
("SampleToolbar", "General", "ToolbarPos", CStr
(msoBarTop)))
.Index = CLng(GetSetting
("SampleToolbar", "General", "ToolbarIndex", 0))
End With

Any help is appreciated! Thanks!

Jaime Rios
 
Back
Top