473,394 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

COM AddIn for Word does not store the position properly

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
Jul 21 '05 #1
8 2982
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" <ja****@nvision-tech.com>
Sender: "Jaime Rios" <ja****@nvision-tech.com>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <a8****************************@phx.gbl>
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


Jul 21 '05 #2
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 [MSFT]" <v-******@online.microsoft.com> wrote in message
news:3U**************@cpmsftngxa06.phx.gbl...
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" <ja****@nvision-tech.com>
Sender: "Jaime Rios" <ja****@nvision-tech.com>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <a8****************************@phx.gbl>
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

Jul 21 '05 #3
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" <ja****@nvision-tech.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
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 [MSFT]" <v-******@online.microsoft.com> wrote in message
news:3U**************@cpmsftngxa06.phx.gbl...
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" <ja****@nvision-tech.com>
Sender: "Jaime Rios" <ja****@nvision-tech.com>
Subject: COM AddIn for Word does not store the position properly
Date: Mon, 22 Sep 2003 06:09:19 -0700
Lines: 26
Message-ID: <a8****************************@phx.gbl>
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


Jul 21 '05 #4
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.msoCont rolButton)
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" <ja****@nvision-tech.com>
References: <a8****************************@phx.gbl> <3U**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP09.phx.gbl>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: <#w**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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" <ja****@nvision-tech.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
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 [MSFT]" <v-******@online.microsoft.com> wrote in message
news:3U**************@cpmsftngxa06.phx.gbl...
> 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 thefind > 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 norights. >
> --------------------
> >Content-Class: urn:content-classes:message
> >From: "Jaime Rios" <ja****@nvision-tech.com>
> >Sender: "Jaime Rios" <ja****@nvision-tech.com>
> >Subject: COM AddIn for Word does not store the position properly
> >Date: Mon, 22 Sep 2003 06:09:19 -0700
> >Lines: 26
> >Message-ID: <a8****************************@phx.gbl>
> >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
> >
> >
> >
>




Jul 21 '05 #5
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 [MSFT]" <v-******@online.microsoft.com> wrote in message
news:tx**************@cpmsftngxa06.phx.gbl...
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.msoCont rolButton)
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" <ja****@nvision-tech.com>
References: <a8****************************@phx.gbl>

<3U**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP09.phx.gbl>
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: <#w**************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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" <ja****@nvision-tech.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
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 [MSFT]" <v-******@online.microsoft.com> wrote in message
news:3U**************@cpmsftngxa06.phx.gbl...
> 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" <ja****@nvision-tech.com>
> >Sender: "Jaime Rios" <ja****@nvision-tech.com>
> >Subject: COM AddIn for Word does not store the position properly
> >Date: Mon, 22 Sep 2003 06:09:19 -0700
> >Lines: 26
> >Message-ID: <a8****************************@phx.gbl>
> >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
> >
> >
> >
>


Jul 21 '05 #6
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/de...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.msoCont rolButton)
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" <ja****@nvision-tech.com>
References: <a8****************************@phx.gbl> <3U**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP09.phx.gbl>
<#w**************@tk2msftngp13.phx.gbl>
<tx**************@cpmsftngxa06.phx.gbl>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: <e7**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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 [MSFT]" <v-******@online.microsoft.com> wrote in message
news:tx**************@cpmsftngxa06.phx.gbl...
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.msoCont rolButton)
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" <ja****@nvision-tech.com>
>References: <a8****************************@phx.gbl>

<3U**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP09.phx.gbl>
>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: <#w**************@tk2msftngp13.phx.gbl>
>Newsgroups: microsoft.public.dotnet.general
>NNTP-Posting-Host: 160.79.12.170
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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 methe >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 = msoBarBottomOr >_
> lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRightThen > ' 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" <ja****@nvision-tech.com> wrote in message
>news:eq**************@TK2MSFTNGP09.phx.gbl...
>> 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 [MSFT]" <v-******@online.microsoft.com> wrote in message
>> news:3U**************@cpmsftngxa06.phx.gbl...
>> > 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" <ja****@nvision-tech.com>
>> > >Sender: "Jaime Rios" <ja****@nvision-tech.com>
>> > >Subject: COM AddIn for Word does not store the position properly
>> > >Date: Mon, 22 Sep 2003 06:09:19 -0700
>> > >Lines: 26
>> > >Message-ID: <a8****************************@phx.gbl>
>> > >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
>> > >
>> > >
>> > >
>> >
>>
>>
>
>
>



Jul 21 '05 #7
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 [MSFT]" <v-******@online.microsoft.com> wrote in message
news:6L**************@cpmsftngxa06.phx.gbl...
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/de...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.msoCont rolButton)
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" <ja****@nvision-tech.com>
References: <a8****************************@phx.gbl>

<3U**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP09.phx.gbl>
<#w**************@tk2msftngp13.phx.gbl>
<tx**************@cpmsftngxa06.phx.gbl>
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: <e7**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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 containnumerical values that are valid, but the code fails when trying to set theproperty. Am I supposed to be doing some sort of typecasting?

Jaime Rios
"Peter Huang [MSFT]" <v-******@online.microsoft.com> wrote in message
news:tx**************@cpmsftngxa06.phx.gbl...
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.msoCont rolButton)
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" <ja****@nvision-tech.com>
>References: <a8****************************@phx.gbl>
<3U**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP09.phx.gbl>
>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: <#w**************@tk2msftngp13.phx.gbl>
>Newsgroups: microsoft.public.dotnet.general
>NNTP-Posting-Host: 160.79.12.170
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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 = msoBarBottomOr
>_
> 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" <ja****@nvision-tech.com> wrote in message
>news:eq**************@TK2MSFTNGP09.phx.gbl...
>> 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 [MSFT]" <v-******@online.microsoft.com> wrote in message >> news:3U**************@cpmsftngxa06.phx.gbl...
>> > 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" <ja****@nvision-tech.com>
>> > >Sender: "Jaime Rios" <ja****@nvision-tech.com>
>> > >Subject: COM AddIn for Word does not store the position properly
>> > >Date: Mon, 22 Sep 2003 06:09:19 -0700
>> > >Lines: 26
>> > >Message-ID: <a8****************************@phx.gbl>
>> > >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
>> > >
>> > >
>> > >
>> >
>>
>>
>
>
>


Jul 21 '05 #8
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" <ja****@nvision-tech.com>
References: <a8****************************@phx.gbl> <3U**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP09.phx.gbl>
<#w**************@tk2msftngp13.phx.gbl>
<tx**************@cpmsftngxa06.phx.gbl>
<e7**************@TK2MSFTNGP11.phx.gbl>
<6L**************@cpmsftngxa06.phx.gbl>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: <#P**************@TK2MSFTNGP12.phx.gbl>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 160.79.12.170
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.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 [MSFT]" <v-******@online.microsoft.com> wrote in message
news:6L**************@cpmsftngxa06.phx.gbl...
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/de...-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.msoCont rolButton)
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" <ja****@nvision-tech.com>
>References: <a8****************************@phx.gbl>

<3U**************@cpmsftngxa06.phx.gbl>
<eq**************@TK2MSFTNGP09.phx.gbl>
<#w**************@tk2msftngp13.phx.gbl>
<tx**************@cpmsftngxa06.phx.gbl>
>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: <e7**************@TK2MSFTNGP11.phx.gbl>
>Newsgroups: microsoft.public.dotnet.general
>NNTP-Posting-Host: 160.79.12.170
>Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.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, thisis >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 variablescontain >numerical values that are valid, but the code fails when trying to setthe >property. Am I supposed to be doing some sort of typecasting?
>
>Jaime Rios
>"Peter Huang [MSFT]" <v-******@online.microsoft.com> wrote in message
>news:tx**************@cpmsftngxa06.phx.gbl...
>> 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.msoCont rolButton)
>> 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" <ja****@nvision-tech.com>
>> >References: <a8****************************@phx.gbl>
>> <3U**************@cpmsftngxa06.phx.gbl>
>> <eq**************@TK2MSFTNGP09.phx.gbl>
>> >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: <#w**************@tk2msftngp13.phx.gbl>
>> >Newsgroups: microsoft.public.dotnet.general
>> >NNTP-Posting-Host: 160.79.12.170
>> >Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.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" <ja****@nvision-tech.com> wrote in message
>> >news:eq**************@TK2MSFTNGP09.phx.gbl...
>> >> 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 fromloading? >> >>
>> >> Jaime
>> >> "Peter Huang [MSFT]" <v-******@online.microsoft.com> wrote inmessage >> >> news:3U**************@cpmsftngxa06.phx.gbl...
>> >> > 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 usingthe >> >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" <ja****@nvision-tech.com>
>> >> > >Sender: "Jaime Rios" <ja****@nvision-tech.com>
>> >> > >Subject: COM AddIn for Word does not store the position properly
>> >> > >Date: Mon, 22 Sep 2003 06:09:19 -0700
>> >> > >Lines: 26
>> >> > >Message-ID: <a8****************************@phx.gbl>
>> >> > >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
>> >> > >
>> >> > >
>> >> > >
>> >> >
>> >>
>> >>
>> >
>> >
>> >
>>
>
>
>



Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: s.subbarayan | last post by:
Dear all, I would like to know the easiest efficient way to set or inject a particular value in the given word or byte?The problem is: I have to implement a function which will set a value from...
0
by: murl | last post by:
I have built a new Word Addin to add a Commandbar at the bottom of word, with buttons on it. I followed all the steps from kb articles and other resources, and told it when debugging to open up the...
0
by: emmett | last post by:
i've created a COM addin for several office applications (word,excel,ppt) and have put a commandbarbutton into each. Clicking this button calls a form. This form acts as a user interface to the...
0
by: maitrepoy | last post by:
Hello I have to create a small addin which works on Powerpoint, Word, Outlook, and Excel on Office 2000, XP, and 2003. This addin consists in adding 2 new Buttons in the "File" Menu of office....
0
by: maitrepoy | last post by:
hello I have to create a small addin which works on Powerpoint, Word, Outlook, and Excel on Office 2000, XP, and 2003. This addin consists in adding 2 new Buttons in the "File" Menu of office....
8
by: Jaime Rios | last post by:
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...
0
by: Srini | last post by:
Hi all Any body have an idea about How to install an Word addin which is developed in VS .Net 2003. i need to install it in my Application which is develpoed in VS.Net 2005. i am getting a watson...
7
by: Joseph Geretz | last post by:
I've been working on an Addin for Outlook in C#. It hasn't been long now, just a couple of days. Suddenly though, running my project in Debug launches Outlook as specified, but no breakpoints...
0
by: Omer | last post by:
I am trying to create a shared addin using visual studio 2005 with the following code. It is working only in Power Point Appliction and not loading in Excel and Word I used the Visual Studio Wizard...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.