COM AddIn for Word does not store the position properly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jaime Rios

    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 "OnConnecti on" function but it fails
    with an error, "Run-time exception thrown :
    System.IO.IOExc eption - Bad file name or number."

    With applicationObje ct.CommandBars( "SampleToolbar" )
    .Left = CLng(GetSetting
    ("SampleToolbar ", "General", "ToolbarLef t", 0))
    .Top = CLng(GetSetting
    ("SampleToolbar ", "General", "ToolbarTop ", 0))
    .Position = CLng(GetSetting
    ("SampleToolbar ", "General", "ToolbarPos ", CStr
    (msoBarTop)))
    .Index = CLng(GetSetting
    ("SampleToolbar ", "General", "ToolbarInd ex", 0))
    End With

    Any help is appreciated! Thanks!

    Jaime Rios


  • Peter Huang [MSFT]

    #2
    RE: COM AddIn for Word does not store the position properly

    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_US ER\Software\VB and VBA Program Settings
    and
    HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Softwar e\VB and
    VBA Program Settings\AppTes t
    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.

    --------------------[color=blue]
    >Content-Class: urn:content-classes:message
    >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
    >Sender: "Jaime Rios" <jaimer@nvisi on-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: <a81901c3810a$b bd32960$a601280 a@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: AcOBCrvTw0D7D7R 6RiqyWJZyUpmpvA ==
    >Newsgroups: microsoft.publi c.dotnet.genera l
    >Path: cpmsftngxa06.ph x.gbl
    >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109406
    >NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
    >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
    >
    >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 "OnConnecti on" function but it fails
    >with an error, "Run-time exception thrown :
    >System.IO.IOEx ception - Bad file name or number."
    >
    >With applicationObje ct.CommandBars( "SampleToolbar" )
    > .Left = CLng(GetSetting
    >("SampleToolba r", "General", "ToolbarLef t", 0))
    > .Top = CLng(GetSetting
    >("SampleToolba r", "General", "ToolbarTop ", 0))
    > .Position = CLng(GetSetting
    >("SampleToolba r", "General", "ToolbarPos ", CStr
    >(msoBarTop)) )
    > .Index = CLng(GetSetting
    >("SampleToolba r", "General", "ToolbarInd ex", 0))
    >End With
    >
    >Any help is appreciated! Thanks!
    >
    >Jaime Rios
    >
    >
    >[/color]

    Comment

    • Jaime Rios

      #3
      Re: COM AddIn for Word does not store the position properly

      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-phuang@online.m icrosoft.com> wrote in message
      news:3URrTTXgDH A.2272@cpmsftng xa06.phx.gbl...[color=blue]
      > 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_US ER\Software\VB and VBA Program Settings
      > and
      > HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Softwar e\VB[/color]
      and[color=blue]
      > VBA Program Settings\AppTes t
      > 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.
      >
      > --------------------[color=green]
      > >Content-Class: urn:content-classes:message
      > >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
      > >Sender: "Jaime Rios" <jaimer@nvisi on-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: <a81901c3810a$b bd32960$a601280 a@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: AcOBCrvTw0D7D7R 6RiqyWJZyUpmpvA ==
      > >Newsgroups: microsoft.publi c.dotnet.genera l
      > >Path: cpmsftngxa06.ph x.gbl
      > >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109406
      > >NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
      > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
      > >
      > >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 "OnConnecti on" function but it fails
      > >with an error, "Run-time exception thrown :
      > >System.IO.IOEx ception - Bad file name or number."
      > >
      > >With applicationObje ct.CommandBars( "SampleToolbar" )
      > > .Left = CLng(GetSetting
      > >("SampleToolba r", "General", "ToolbarLef t", 0))
      > > .Top = CLng(GetSetting
      > >("SampleToolba r", "General", "ToolbarTop ", 0))
      > > .Position = CLng(GetSetting
      > >("SampleToolba r", "General", "ToolbarPos ", CStr
      > >(msoBarTop)) )
      > > .Index = CLng(GetSetting
      > >("SampleToolba r", "General", "ToolbarInd ex", 0))
      > >End With
      > >
      > >Any help is appreciated! Thanks!
      > >
      > >Jaime Rios
      > >
      > >
      > >[/color]
      >[/color]


      Comment

      • Jaime Rios

        #4
        Re: COM AddIn for Word does not store the position properly

        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",
        "ToolbarInd ex", 0))
        lToolbarLeft = CLng(GetSetting ("SampleToolbar ", "General",
        "ToolbarLef t", 100))
        lToolbarTop = CLng(GetSetting ("SampleToolbar ", "General",
        "ToolbarTop ", 100))

        With applicationObje ct.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" <jaimer@nvisi on-tech.com> wrote in message
        news:eqN0$MegDH A.1760@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Now I am having a problem where the COM AddIn will not load at all! Is[/color]
        there[color=blue]
        > a setting or something that Word has done to prevent it from loading?
        >
        > Jaime
        > "Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
        > news:3URrTTXgDH A.2272@cpmsftng xa06.phx.gbl...[color=green]
        > > 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_US ER\Software\VB and VBA Program Settings
        > > and
        > > HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Softwar e\VB[/color]
        > and[color=green]
        > > VBA Program Settings\AppTes t
        > > the <> section may be different from yours. You may search using the[/color][/color]
        find[color=blue][color=green]
        > > 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[/color][/color]
        rights.[color=blue][color=green]
        > >
        > > --------------------[color=darkred]
        > > >Content-Class: urn:content-classes:message
        > > >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
        > > >Sender: "Jaime Rios" <jaimer@nvisi on-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: <a81901c3810a$b bd32960$a601280 a@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: AcOBCrvTw0D7D7R 6RiqyWJZyUpmpvA ==
        > > >Newsgroups: microsoft.publi c.dotnet.genera l
        > > >Path: cpmsftngxa06.ph x.gbl
        > > >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109406
        > > >NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
        > > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
        > > >
        > > >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 "OnConnecti on" function but it fails
        > > >with an error, "Run-time exception thrown :
        > > >System.IO.IOEx ception - Bad file name or number."
        > > >
        > > >With applicationObje ct.CommandBars( "SampleToolbar" )
        > > > .Left = CLng(GetSetting
        > > >("SampleToolba r", "General", "ToolbarLef t", 0))
        > > > .Top = CLng(GetSetting
        > > >("SampleToolba r", "General", "ToolbarTop ", 0))
        > > > .Position = CLng(GetSetting
        > > >("SampleToolba r", "General", "ToolbarPos ", CStr
        > > >(msoBarTop)) )
        > > > .Index = CLng(GetSetting
        > > >("SampleToolba r", "General", "ToolbarInd ex", 0))
        > > >End With
        > > >
        > > >Any help is appreciated! Thanks!
        > > >
        > > >Jaime Rios
        > > >
        > > >
        > > >[/color]
        > >[/color]
        >
        >[/color]


        Comment

        • Peter Huang [MSFT]

          #5
          Re: COM AddIn for Word does not store the position properly

          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.Offic e.Interop.Word
          Imports Office = Microsoft.Offic e.Core
          Module Module1
          Sub Main()
          Dim MyButton As Office.CommandB arButton
          Dim wdApp As Word.Applicatio n
          Dim oCmdBars As Office.CommandB ars
          Dim oCmdBar As Office.CommandB ar
          wdApp = New Word.Applicatio nClass
          wdApp.Documents .Add()
          wdApp.Visible = True
          oCmdBars = wdApp.CommandBa rs
          oCmdBar = wdApp.CommandBa rs.Add("My CommandBar",
          Office.MsoBarPo sition.msoBarBo ttom, False, True)
          oCmdBars("My CommandBar").Vi sible = True
          oCmdBar.Left = 100
          oCmdBar.RowInde x = 3
          MyButton =
          oCmdBar.Control s.Add(Office.Ms oControlType.ms oControlButton)
          MyButton.Captio n = "My Custom Button"
          MyButton.Style = Office.MsoButto nStyle.msoButto nCaption
          wdApp.ActiveDoc ument.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.

          --------------------[color=blue]
          >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
          >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>[/color]
          <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
          <eqN0$MegDHA.17 60@TK2MSFTNGP09 .phx.gbl>[color=blue]
          >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: <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
          >Newsgroups: microsoft.publi c.dotnet.genera l
          >NNTP-Posting-Host: 160.79.12.170
          >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
          >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109595
          >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
          >
          >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 applicationObje ct.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" <jaimer@nvisi on-tech.com> wrote in message
          >news:eqN0$MegD HA.1760@TK2MSFT NGP09.phx.gbl.. .[color=green]
          >> Now I am having a problem where the COM AddIn will not load at all! Is[/color]
          >there[color=green]
          >> a setting or something that Word has done to prevent it from loading?
          >>
          >> Jaime
          >> "Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
          >> news:3URrTTXgDH A.2272@cpmsftng xa06.phx.gbl...[color=darkred]
          >> > 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_US ER\Software\VB and VBA Program Settings
          >> > and
          >> > HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Softwar e\VB[/color]
          >> and[color=darkred]
          >> > VBA Program Settings\AppTes t
          >> > the <> section may be different from yours. You may search using the[/color][/color]
          >find[color=green][color=darkred]
          >> > function in the regedit.
          >> >
          >> > I suggest that you break the with-endwith section into four code line[/color][/color][/color]
          to[color=blue][color=green][color=darkred]
          >> > see which function cause the error.
          >> > Since it seems the error you got is related with the File System, do[/color][/color][/color]
          you[color=blue][color=green][color=darkred]
          >> > 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[/color][/color]
          >rights.[color=green][color=darkred]
          >> >
          >> > --------------------
          >> > >Content-Class: urn:content-classes:message
          >> > >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
          >> > >Sender: "Jaime Rios" <jaimer@nvisi on-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: <a81901c3810a$b bd32960$a601280 a@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: AcOBCrvTw0D7D7R 6RiqyWJZyUpmpvA ==
          >> > >Newsgroups: microsoft.publi c.dotnet.genera l
          >> > >Path: cpmsftngxa06.ph x.gbl
          >> > >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109406
          >> > >NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
          >> > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
          >> > >
          >> > >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 "OnConnecti on" function but it fails
          >> > >with an error, "Run-time exception thrown :
          >> > >System.IO.IOEx ception - Bad file name or number."
          >> > >
          >> > >With applicationObje ct.CommandBars( "SampleToolbar" )
          >> > > .Left = CLng(GetSetting
          >> > >("SampleToolba r", "General", "ToolbarLef t", 0))
          >> > > .Top = CLng(GetSetting
          >> > >("SampleToolba r", "General", "ToolbarTop ", 0))
          >> > > .Position = CLng(GetSetting
          >> > >("SampleToolba r", "General", "ToolbarPos ", CStr
          >> > >(msoBarTop)) )
          >> > > .Index = CLng(GetSetting
          >> > >("SampleToolba r", "General", "ToolbarInd ex", 0))
          >> > >End With
          >> > >
          >> > >Any help is appreciated! Thanks!
          >> > >
          >> > >Jaime Rios
          >> > >
          >> > >
          >> > >
          >> >[/color]
          >>
          >>[/color]
          >
          >
          >[/color]

          Comment

          • Jaime Rios

            #6
            Re: COM AddIn for Word does not store the position properly

            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-phuang@online.m icrosoft.com> wrote in message
            news:txsT46mgDH A.2188@cpmsftng xa06.phx.gbl...[color=blue]
            > 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.Offic e.Interop.Word
            > Imports Office = Microsoft.Offic e.Core
            > Module Module1
            > Sub Main()
            > Dim MyButton As Office.CommandB arButton
            > Dim wdApp As Word.Applicatio n
            > Dim oCmdBars As Office.CommandB ars
            > Dim oCmdBar As Office.CommandB ar
            > wdApp = New Word.Applicatio nClass
            > wdApp.Documents .Add()
            > wdApp.Visible = True
            > oCmdBars = wdApp.CommandBa rs
            > oCmdBar = wdApp.CommandBa rs.Add("My CommandBar",
            > Office.MsoBarPo sition.msoBarBo ttom, False, True)
            > oCmdBars("My CommandBar").Vi sible = True
            > oCmdBar.Left = 100
            > oCmdBar.RowInde x = 3
            > MyButton =
            > oCmdBar.Control s.Add(Office.Ms oControlType.ms oControlButton)
            > MyButton.Captio n = "My Custom Button"
            > MyButton.Style = Office.MsoButto nStyle.msoButto nCaption
            > wdApp.ActiveDoc ument.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.
            >
            > --------------------[color=green]
            > >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
            > >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>[/color]
            > <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
            > <eqN0$MegDHA.17 60@TK2MSFTNGP09 .phx.gbl>[color=green]
            > >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: <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
            > >Newsgroups: microsoft.publi c.dotnet.genera l
            > >NNTP-Posting-Host: 160.79.12.170
            > >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
            > >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109595
            > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
            > >
            > >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[/color][/color]
            the[color=blue][color=green]
            > >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 applicationObje ct.CommandBars( "Sample Toolbar")
            > > If lToolbarPos = msoBarTop Or lToolbarPos = msoBarBottom[/color][/color]
            Or[color=blue][color=green]
            > >_
            > > lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight[/color][/color]
            Then[color=blue][color=green]
            > > ' 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" <jaimer@nvisi on-tech.com> wrote in message
            > >news:eqN0$MegD HA.1760@TK2MSFT NGP09.phx.gbl.. .[color=darkred]
            > >> Now I am having a problem where the COM AddIn will not load at all! Is[/color]
            > >there[color=darkred]
            > >> a setting or something that Word has done to prevent it from loading?
            > >>
            > >> Jaime
            > >> "Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
            > >> news:3URrTTXgDH A.2272@cpmsftng xa06.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_US ER\Software\VB and VBA Program Settings
            > >> > and
            > >> >[/color][/color][/color]
            HKEY_USERS\<S-1-5-21-2146773085-903363285-719344707-166692>\Softwar e\VB[color=blue][color=green][color=darkred]
            > >> and
            > >> > VBA Program Settings\AppTes t
            > >> > the <> section may be different from yours. You may search using the[/color]
            > >find[color=darkred]
            > >> > function in the regedit.
            > >> >
            > >> > I suggest that you break the with-endwith section into four code line[/color][/color]
            > to[color=green][color=darkred]
            > >> > see which function cause the error.
            > >> > Since it seems the error you got is related with the File System, do[/color][/color]
            > you[color=green][color=darkred]
            > >> > 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[/color]
            > >rights.[color=darkred]
            > >> >
            > >> > --------------------
            > >> > >Content-Class: urn:content-classes:message
            > >> > >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
            > >> > >Sender: "Jaime Rios" <jaimer@nvisi on-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: <a81901c3810a$b bd32960$a601280 a@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: AcOBCrvTw0D7D7R 6RiqyWJZyUpmpvA ==
            > >> > >Newsgroups: microsoft.publi c.dotnet.genera l
            > >> > >Path: cpmsftngxa06.ph x.gbl
            > >> > >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109406
            > >> > >NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
            > >> > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
            > >> > >
            > >> > >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 "OnConnecti on" function but it fails
            > >> > >with an error, "Run-time exception thrown :
            > >> > >System.IO.IOEx ception - Bad file name or number."
            > >> > >
            > >> > >With applicationObje ct.CommandBars( "SampleToolbar" )
            > >> > > .Left = CLng(GetSetting
            > >> > >("SampleToolba r", "General", "ToolbarLef t", 0))
            > >> > > .Top = CLng(GetSetting
            > >> > >("SampleToolba r", "General", "ToolbarTop ", 0))
            > >> > > .Position = CLng(GetSetting
            > >> > >("SampleToolba r", "General", "ToolbarPos ", CStr
            > >> > >(msoBarTop)) )
            > >> > > .Index = CLng(GetSetting
            > >> > >("SampleToolba r", "General", "ToolbarInd ex", 0))
            > >> > >End With
            > >> > >
            > >> > >Any help is appreciated! Thanks!
            > >> > >
            > >> > >Jaime Rios
            > >> > >
            > >> > >
            > >> > >
            > >> >
            > >>
            > >>[/color]
            > >
            > >
            > >[/color]
            >[/color]


            Comment

            • Peter Huang [MSFT]

              #7
              Re: COM AddIn for Word does not store the position properly

              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,8 54,775,808 through 9,223,372,036,8 54,775,807.

              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.Offic e.Core.CommandB ar

              Imports Word = Microsoft.Offic e.Interop.Word
              Imports Office = Microsoft.Offic e.Core
              Module Module1
              Sub Main()
              SaveSetting("Sa mpleToolbar", "General", "ToolbarPos ", 100)
              Dim MyButton As Office.CommandB arButton
              Dim wdApp As Word.Applicatio n
              Dim oCmdBars As Office.CommandB ars
              Dim oCmdBar As Office.CommandB ar
              wdApp = New Word.Applicatio nClass
              wdApp.Documents .Add()
              wdApp.Visible = True
              oCmdBars = wdApp.CommandBa rs
              oCmdBar = wdApp.CommandBa rs.Add("My CommandBar",
              Office.MsoBarPo sition.msoBarBo ttom, False, True)
              oCmdBars("My CommandBar").Vi sible = True
              oCmdBar.Left = 100
              oCmdBar.RowInde x = 3
              Dim tp As Integer = GetSetting("Sam pleToolbar", "General",
              "ToolbarPos ")
              oCmdBar.Top = tp
              MyButton =
              oCmdBar.Control s.Add(Office.Ms oControlType.ms oControlButton)
              MyButton.Captio n = "My Custom Button"
              MyButton.Style = Office.MsoButto nStyle.msoButto nCaption
              wdApp.ActiveDoc ument.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.

              --------------------[color=blue]
              >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
              >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>[/color]
              <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
              <eqN0$MegDHA.17 60@TK2MSFTNGP09 .phx.gbl>
              <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
              <txsT46mgDHA.21 88@cpmsftngxa06 .phx.gbl>[color=blue]
              >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: <e70Dh2pgDHA.40 24@TK2MSFTNGP11 .phx.gbl>
              >Newsgroups: microsoft.publi c.dotnet.genera l
              >NNTP-Posting-Host: 160.79.12.170
              >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
              >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109734
              >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
              >
              >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-phuang@online.m icrosoft.com> wrote in message
              >news:txsT46mgD HA.2188@cpmsftn gxa06.phx.gbl.. .[color=green]
              >> 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.Offic e.Interop.Word
              >> Imports Office = Microsoft.Offic e.Core
              >> Module Module1
              >> Sub Main()
              >> Dim MyButton As Office.CommandB arButton
              >> Dim wdApp As Word.Applicatio n
              >> Dim oCmdBars As Office.CommandB ars
              >> Dim oCmdBar As Office.CommandB ar
              >> wdApp = New Word.Applicatio nClass
              >> wdApp.Documents .Add()
              >> wdApp.Visible = True
              >> oCmdBars = wdApp.CommandBa rs
              >> oCmdBar = wdApp.CommandBa rs.Add("My CommandBar",
              >> Office.MsoBarPo sition.msoBarBo ttom, False, True)
              >> oCmdBars("My CommandBar").Vi sible = True
              >> oCmdBar.Left = 100
              >> oCmdBar.RowInde x = 3
              >> MyButton =
              >> oCmdBar.Control s.Add(Office.Ms oControlType.ms oControlButton)
              >> MyButton.Captio n = "My Custom Button"
              >> MyButton.Style = Office.MsoButto nStyle.msoButto nCaption
              >> wdApp.ActiveDoc ument.Saved = True
              >> wdApp.Quit()
              >> wdApp = Nothing
              >> End Sub
              >> End Module
              >>
              >> To debug the code in the command application,e.g . a console application[/color][/color]
              or[color=blue][color=green]
              >> 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[/color][/color]
              rights.[color=blue][color=green]
              >>
              >> --------------------[color=darkred]
              >> >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
              >> >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>[/color]
              >> <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
              >> <eqN0$MegDHA.17 60@TK2MSFTNGP09 .phx.gbl>[color=darkred]
              >> >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: <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
              >> >Newsgroups: microsoft.publi c.dotnet.genera l
              >> >NNTP-Posting-Host: 160.79.12.170
              >> >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
              >> >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109595
              >> >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
              >> >
              >> >Figured this one out, the COM AddIn was disabled under the disabled[/color][/color][/color]
              items[color=blue][color=green][color=darkred]
              >> >button in the Help->About Word dialog box. But I am still having[/color][/color][/color]
              problems[color=blue][color=green][color=darkred]
              >> >setting the toolbar position. Here is the code, but it keeps giving me[/color][/color]
              >the[color=green][color=darkred]
              >> >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 applicationObje ct.CommandBars( "Sample Toolbar")
              >> > If lToolbarPos = msoBarTop Or lToolbarPos = msoBarBottom[/color][/color]
              >Or[color=green][color=darkred]
              >> >_
              >> > lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight[/color][/color]
              >Then[color=green][color=darkred]
              >> > ' 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" <jaimer@nvisi on-tech.com> wrote in message
              >> >news:eqN0$MegD HA.1760@TK2MSFT NGP09.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-phuang@online.m icrosoft.com> wrote in message
              >> >> news:3URrTTXgDH A.2272@cpmsftng xa06.phx.gbl...
              >> >> > Hi Jaime,
              >> >> >
              >> >> > You may try to check if the Registry setting has been set. [using[/color][/color][/color]
              the[color=blue][color=green][color=darkred]
              >> >> > regedit tool]
              >> >> > The setting is usually under the Key
              >> >> > HKEY_CURRENT_US ER\Software\VB and VBA Program Settings
              >> >> > and
              >> >> >[/color][/color]
              >HKEY_USERS\< S-1-5-21-2146773085-903363285-719344707-166692>\Softwar e\VB[color=green][color=darkred]
              >> >> and
              >> >> > VBA Program Settings\AppTes t
              >> >> > 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[/color][/color][/color]
              line[color=blue][color=green]
              >> to[color=darkred]
              >> >> > see which function cause the error.
              >> >> > Since it seems the error you got is related with the File System, do[/color]
              >> you[color=darkred]
              >> >> > 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" <jaimer@nvisi on-tech.com>
              >> >> > >Sender: "Jaime Rios" <jaimer@nvisi on-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: <a81901c3810a$b bd32960$a601280 a@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: AcOBCrvTw0D7D7R 6RiqyWJZyUpmpvA ==
              >> >> > >Newsgroups: microsoft.publi c.dotnet.genera l
              >> >> > >Path: cpmsftngxa06.ph x.gbl
              >> >> > >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109406
              >> >> > >NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
              >> >> > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
              >> >> > >
              >> >> > >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 "OnConnecti on" function but it fails
              >> >> > >with an error, "Run-time exception thrown :
              >> >> > >System.IO.IOEx ception - Bad file name or number."
              >> >> > >
              >> >> > >With applicationObje ct.CommandBars( "SampleToolbar" )
              >> >> > > .Left = CLng(GetSetting
              >> >> > >("SampleToolba r", "General", "ToolbarLef t", 0))
              >> >> > > .Top = CLng(GetSetting
              >> >> > >("SampleToolba r", "General", "ToolbarTop ", 0))
              >> >> > > .Position = CLng(GetSetting
              >> >> > >("SampleToolba r", "General", "ToolbarPos ", CStr
              >> >> > >(msoBarTop)) )
              >> >> > > .Index = CLng(GetSetting
              >> >> > >("SampleToolba r", "General", "ToolbarInd ex", 0))
              >> >> > >End With
              >> >> > >
              >> >> > >Any help is appreciated! Thanks!
              >> >> > >
              >> >> > >Jaime Rios
              >> >> > >
              >> >> > >
              >> >> > >
              >> >> >
              >> >>
              >> >>
              >> >
              >> >
              >> >[/color]
              >>[/color]
              >
              >
              >[/color]

              Comment

              • Jaime Rios

                #8
                Re: COM AddIn for Word does not store the position properly

                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-phuang@online.m icrosoft.com> wrote in message
                news:6Lge9NxgDH A.2076@cpmsftng xa06.phx.gbl...[color=blue]
                > 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,8 54,775,808 through 9,223,372,036,8 54,775,807.
                >[/color]
                http://msdn.microsoft.com/library/de...us/vblr7/html/[color=blue]
                > 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.Offic e.Core.CommandB ar
                >
                > Imports Word = Microsoft.Offic e.Interop.Word
                > Imports Office = Microsoft.Offic e.Core
                > Module Module1
                > Sub Main()
                > SaveSetting("Sa mpleToolbar", "General", "ToolbarPos ", 100)
                > Dim MyButton As Office.CommandB arButton
                > Dim wdApp As Word.Applicatio n
                > Dim oCmdBars As Office.CommandB ars
                > Dim oCmdBar As Office.CommandB ar
                > wdApp = New Word.Applicatio nClass
                > wdApp.Documents .Add()
                > wdApp.Visible = True
                > oCmdBars = wdApp.CommandBa rs
                > oCmdBar = wdApp.CommandBa rs.Add("My CommandBar",
                > Office.MsoBarPo sition.msoBarBo ttom, False, True)
                > oCmdBars("My CommandBar").Vi sible = True
                > oCmdBar.Left = 100
                > oCmdBar.RowInde x = 3
                > Dim tp As Integer = GetSetting("Sam pleToolbar", "General",
                > "ToolbarPos ")
                > oCmdBar.Top = tp
                > MyButton =
                > oCmdBar.Control s.Add(Office.Ms oControlType.ms oControlButton)
                > MyButton.Captio n = "My Custom Button"
                > MyButton.Style = Office.MsoButto nStyle.msoButto nCaption
                > wdApp.ActiveDoc ument.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.
                >
                > --------------------[color=green]
                > >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
                > >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>[/color]
                > <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
                > <eqN0$MegDHA.17 60@TK2MSFTNGP09 .phx.gbl>
                > <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
                > <txsT46mgDHA.21 88@cpmsftngxa06 .phx.gbl>[color=green]
                > >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: <e70Dh2pgDHA.40 24@TK2MSFTNGP11 .phx.gbl>
                > >Newsgroups: microsoft.publi c.dotnet.genera l
                > >NNTP-Posting-Host: 160.79.12.170
                > >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
                > >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109734
                > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
                > >
                > >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[/color][/color]
                is[color=blue][color=green]
                > >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[/color][/color]
                contain[color=blue][color=green]
                > >numerical values that are valid, but the code fails when trying to set[/color][/color]
                the[color=blue][color=green]
                > >property. Am I supposed to be doing some sort of typecasting?
                > >
                > >Jaime Rios
                > >"Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
                > >news:txsT46mgD HA.2188@cpmsftn gxa06.phx.gbl.. .[color=darkred]
                > >> 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.Offic e.Interop.Word
                > >> Imports Office = Microsoft.Offic e.Core
                > >> Module Module1
                > >> Sub Main()
                > >> Dim MyButton As Office.CommandB arButton
                > >> Dim wdApp As Word.Applicatio n
                > >> Dim oCmdBars As Office.CommandB ars
                > >> Dim oCmdBar As Office.CommandB ar
                > >> wdApp = New Word.Applicatio nClass
                > >> wdApp.Documents .Add()
                > >> wdApp.Visible = True
                > >> oCmdBars = wdApp.CommandBa rs
                > >> oCmdBar = wdApp.CommandBa rs.Add("My CommandBar",
                > >> Office.MsoBarPo sition.msoBarBo ttom, False, True)
                > >> oCmdBars("My CommandBar").Vi sible = True
                > >> oCmdBar.Left = 100
                > >> oCmdBar.RowInde x = 3
                > >> MyButton =
                > >> oCmdBar.Control s.Add(Office.Ms oControlType.ms oControlButton)
                > >> MyButton.Captio n = "My Custom Button"
                > >> MyButton.Style = Office.MsoButto nStyle.msoButto nCaption
                > >> wdApp.ActiveDoc ument.Saved = True
                > >> wdApp.Quit()
                > >> wdApp = Nothing
                > >> End Sub
                > >> End Module
                > >>
                > >> To debug the code in the command application,e.g . a console application[/color][/color]
                > or[color=green][color=darkred]
                > >> 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[/color][/color]
                > rights.[color=green][color=darkred]
                > >>
                > >> --------------------
                > >> >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
                > >> >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>
                > >> <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
                > >> <eqN0$MegDHA.17 60@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: <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
                > >> >Newsgroups: microsoft.publi c.dotnet.genera l
                > >> >NNTP-Posting-Host: 160.79.12.170
                > >> >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
                > >> >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109595
                > >> >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
                > >> >
                > >> >Figured this one out, the COM AddIn was disabled under the disabled[/color][/color]
                > items[color=green][color=darkred]
                > >> >button in the Help->About Word dialog box. But I am still having[/color][/color]
                > problems[color=green][color=darkred]
                > >> >setting the toolbar position. Here is the code, but it keeps giving me[/color]
                > >the[color=darkred]
                > >> >error:
                > >> >
                > >> >Error of type: 458 has occurred.
                > >> >Desc: Bad variable type
                > >> >When I try to set the position properties! Any ideas? Thanks in[/color][/color][/color]
                advance![color=blue][color=green][color=darkred]
                > >> >
                > >> > 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 ",[/color][/color][/color]
                "General",[color=blue][color=green][color=darkred]
                > >> >"ToolbarIndex" , 0))
                > >> > lToolbarLeft = CLng(GetSetting ("SampleToolbar ", "General",
                > >> >"ToolbarLeft ", 100))
                > >> > lToolbarTop = CLng(GetSetting ("SampleToolbar ", "General",
                > >> >"ToolbarTop" , 100))
                > >> >
                > >> > With applicationObje ct.CommandBars( "Sample Toolbar")
                > >> > If lToolbarPos = msoBarTop Or lToolbarPos =[/color][/color][/color]
                msoBarBottom[color=blue][color=green]
                > >Or[color=darkred]
                > >> >_
                > >> > lToolbarPos = msoBarLeft Or lToolbarPos = msoBarRight[/color]
                > >Then[color=darkred]
                > >> > ' 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" <jaimer@nvisi on-tech.com> wrote in message
                > >> >news:eqN0$MegD HA.1760@TK2MSFT NGP09.phx.gbl.. .
                > >> >> Now I am having a problem where the COM AddIn will not load at all![/color][/color][/color]
                Is[color=blue][color=green][color=darkred]
                > >> >there
                > >> >> a setting or something that Word has done to prevent it from[/color][/color][/color]
                loading?[color=blue][color=green][color=darkred]
                > >> >>
                > >> >> Jaime
                > >> >> "Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in[/color][/color][/color]
                message[color=blue][color=green][color=darkred]
                > >> >> news:3URrTTXgDH A.2272@cpmsftng xa06.phx.gbl...
                > >> >> > Hi Jaime,
                > >> >> >
                > >> >> > You may try to check if the Registry setting has been set. [using[/color][/color]
                > the[color=green][color=darkred]
                > >> >> > regedit tool]
                > >> >> > The setting is usually under the Key
                > >> >> > HKEY_CURRENT_US ER\Software\VB and VBA Program Settings
                > >> >> > and
                > >> >> >[/color]
                > >HKEY_USERS\< S-1-5-21-2146773085-903363285-719344707-166692>\Softwar e\VB[color=darkred]
                > >> >> and
                > >> >> > VBA Program Settings\AppTes t
                > >> >> > the <> section may be different from yours. You may search using[/color][/color][/color]
                the[color=blue][color=green][color=darkred]
                > >> >find
                > >> >> > function in the regedit.
                > >> >> >
                > >> >> > I suggest that you break the with-endwith section into four code[/color][/color]
                > line[color=green][color=darkred]
                > >> to
                > >> >> > see which function cause the error.
                > >> >> > Since it seems the error you got is related with the File System,[/color][/color][/color]
                do[color=blue][color=green][color=darkred]
                > >> 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" <jaimer@nvisi on-tech.com>
                > >> >> > >Sender: "Jaime Rios" <jaimer@nvisi on-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: <a81901c3810a$b bd32960$a601280 a@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: AcOBCrvTw0D7D7R 6RiqyWJZyUpmpvA ==
                > >> >> > >Newsgroups: microsoft.publi c.dotnet.genera l
                > >> >> > >Path: cpmsftngxa06.ph x.gbl
                > >> >> > >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109406
                > >> >> > >NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
                > >> >> > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
                > >> >> > >
                > >> >> > >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 "OnConnecti on" function but it fails
                > >> >> > >with an error, "Run-time exception thrown :
                > >> >> > >System.IO.IOEx ception - Bad file name or number."
                > >> >> > >
                > >> >> > >With applicationObje ct.CommandBars( "SampleToolbar" )
                > >> >> > > .Left = CLng(GetSetting
                > >> >> > >("SampleToolba r", "General", "ToolbarLef t", 0))
                > >> >> > > .Top = CLng(GetSetting
                > >> >> > >("SampleToolba r", "General", "ToolbarTop ", 0))
                > >> >> > > .Position = CLng(GetSetting
                > >> >> > >("SampleToolba r", "General", "ToolbarPos ", CStr
                > >> >> > >(msoBarTop)) )
                > >> >> > > .Index = CLng(GetSetting
                > >> >> > >("SampleToolba r", "General", "ToolbarInd ex", 0))
                > >> >> > >End With
                > >> >> > >
                > >> >> > >Any help is appreciated! Thanks!
                > >> >> > >
                > >> >> > >Jaime Rios
                > >> >> > >
                > >> >> > >
                > >> >> > >
                > >> >> >
                > >> >>
                > >> >>
                > >> >
                > >> >
                > >> >
                > >>[/color]
                > >
                > >
                > >[/color]
                >[/color]


                Comment

                • Peter Huang [MSFT]

                  #9
                  Re: COM AddIn for Word does not store the position properly

                  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.

                  --------------------[color=blue]
                  >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
                  >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>[/color]
                  <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
                  <eqN0$MegDHA.17 60@TK2MSFTNGP09 .phx.gbl>
                  <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
                  <txsT46mgDHA.21 88@cpmsftngxa06 .phx.gbl>
                  <e70Dh2pgDHA.40 24@TK2MSFTNGP11 .phx.gbl>
                  <6Lge9NxgDHA.20 76@cpmsftngxa06 .phx.gbl>[color=blue]
                  >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: <#PfrPC5gDHA.21 24@TK2MSFTNGP12 .phx.gbl>
                  >Newsgroups: microsoft.publi c.dotnet.genera l
                  >NNTP-Posting-Host: 160.79.12.170
                  >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
                  >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109906
                  >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
                  >
                  >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-phuang@online.m icrosoft.com> wrote in message
                  >news:6Lge9NxgD HA.2076@cpmsftn gxa06.phx.gbl.. .[color=green]
                  >> 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,8 54,775,808 through 9,223,372,036,8 54,775,807.
                  >>[/color]
                  >http://msdn.microsoft.com/library/de...-us/vblr7/html[/color]
                  /[color=blue][color=green]
                  >> 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.Offic e.Core.CommandB ar
                  >>
                  >> Imports Word = Microsoft.Offic e.Interop.Word
                  >> Imports Office = Microsoft.Offic e.Core
                  >> Module Module1
                  >> Sub Main()
                  >> SaveSetting("Sa mpleToolbar", "General", "ToolbarPos ", 100)
                  >> Dim MyButton As Office.CommandB arButton
                  >> Dim wdApp As Word.Applicatio n
                  >> Dim oCmdBars As Office.CommandB ars
                  >> Dim oCmdBar As Office.CommandB ar
                  >> wdApp = New Word.Applicatio nClass
                  >> wdApp.Documents .Add()
                  >> wdApp.Visible = True
                  >> oCmdBars = wdApp.CommandBa rs
                  >> oCmdBar = wdApp.CommandBa rs.Add("My CommandBar",
                  >> Office.MsoBarPo sition.msoBarBo ttom, False, True)
                  >> oCmdBars("My CommandBar").Vi sible = True
                  >> oCmdBar.Left = 100
                  >> oCmdBar.RowInde x = 3
                  >> Dim tp As Integer = GetSetting("Sam pleToolbar", "General",
                  >> "ToolbarPos ")
                  >> oCmdBar.Top = tp
                  >> MyButton =
                  >> oCmdBar.Control s.Add(Office.Ms oControlType.ms oControlButton)
                  >> MyButton.Captio n = "My Custom Button"
                  >> MyButton.Style = Office.MsoButto nStyle.msoButto nCaption
                  >> wdApp.ActiveDoc ument.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[/color][/color]
                  rights.[color=blue][color=green]
                  >>
                  >> --------------------[color=darkred]
                  >> >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
                  >> >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>[/color]
                  >> <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
                  >> <eqN0$MegDHA.17 60@TK2MSFTNGP09 .phx.gbl>
                  >> <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
                  >> <txsT46mgDHA.21 88@cpmsftngxa06 .phx.gbl>[color=darkred]
                  >> >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: <e70Dh2pgDHA.40 24@TK2MSFTNGP11 .phx.gbl>
                  >> >Newsgroups: microsoft.publi c.dotnet.genera l
                  >> >NNTP-Posting-Host: 160.79.12.170
                  >> >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
                  >> >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109734
                  >> >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
                  >> >
                  >> >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[/color][/color]
                  >is[color=green][color=darkred]
                  >> >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[/color][/color]
                  >contain[color=green][color=darkred]
                  >> >numerical values that are valid, but the code fails when trying to set[/color][/color]
                  >the[color=green][color=darkred]
                  >> >property. Am I supposed to be doing some sort of typecasting?
                  >> >
                  >> >Jaime Rios
                  >> >"Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in message
                  >> >news:txsT46mgD HA.2188@cpmsftn gxa06.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.Offic e.Interop.Word
                  >> >> Imports Office = Microsoft.Offic e.Core
                  >> >> Module Module1
                  >> >> Sub Main()
                  >> >> Dim MyButton As Office.CommandB arButton
                  >> >> Dim wdApp As Word.Applicatio n
                  >> >> Dim oCmdBars As Office.CommandB ars
                  >> >> Dim oCmdBar As Office.CommandB ar
                  >> >> wdApp = New Word.Applicatio nClass
                  >> >> wdApp.Documents .Add()
                  >> >> wdApp.Visible = True
                  >> >> oCmdBars = wdApp.CommandBa rs
                  >> >> oCmdBar = wdApp.CommandBa rs.Add("My CommandBar",
                  >> >> Office.MsoBarPo sition.msoBarBo ttom, False, True)
                  >> >> oCmdBars("My CommandBar").Vi sible = True
                  >> >> oCmdBar.Left = 100
                  >> >> oCmdBar.RowInde x = 3
                  >> >> MyButton =
                  >> >> oCmdBar.Control s.Add(Office.Ms oControlType.ms oControlButton)
                  >> >> MyButton.Captio n = "My Custom Button"
                  >> >> MyButton.Style = Office.MsoButto nStyle.msoButto nCaption
                  >> >> wdApp.ActiveDoc ument.Saved = True
                  >> >> wdApp.Quit()
                  >> >> wdApp = Nothing
                  >> >> End Sub
                  >> >> End Module
                  >> >>
                  >> >> To debug the code in the command application,e.g . a console[/color][/color][/color]
                  application[color=blue][color=green]
                  >> or[color=darkred]
                  >> >> 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[/color]
                  >> rights.[color=darkred]
                  >> >>
                  >> >> --------------------
                  >> >> >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
                  >> >> >References: <a81901c3810a$b bd32960$a601280 a@phx.gbl>
                  >> >> <3URrTTXgDHA.22 72@cpmsftngxa06 .phx.gbl>
                  >> >> <eqN0$MegDHA.17 60@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: <#wHVWgegDHA.35 32@tk2msftngp13 .phx.gbl>
                  >> >> >Newsgroups: microsoft.publi c.dotnet.genera l
                  >> >> >NNTP-Posting-Host: 160.79.12.170
                  >> >> >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
                  >> >> >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:109595
                  >> >> >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
                  >> >> >
                  >> >> >Figured this one out, the COM AddIn was disabled under the disabled[/color]
                  >> items[color=darkred]
                  >> >> >button in the Help->About Word dialog box. But I am still having[/color]
                  >> problems[color=darkred]
                  >> >> >setting the toolbar position. Here is the code, but it keeps giving[/color][/color][/color]
                  me[color=blue][color=green][color=darkred]
                  >> >the
                  >> >> >error:
                  >> >> >
                  >> >> >Error of type: 458 has occurred.
                  >> >> >Desc: Bad variable type
                  >> >> >When I try to set the position properties! Any ideas? Thanks in[/color][/color]
                  >advance![color=green][color=darkred]
                  >> >> >
                  >> >> > 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 ",[/color][/color]
                  >"General",[color=green][color=darkred]
                  >> >> >"ToolbarIndex" , 0))
                  >> >> > lToolbarLeft = CLng(GetSetting ("SampleToolbar ",[/color][/color][/color]
                  "General",[color=blue][color=green][color=darkred]
                  >> >> >"ToolbarLeft ", 100))
                  >> >> > lToolbarTop = CLng(GetSetting ("SampleToolbar ", "General",
                  >> >> >"ToolbarTop" , 100))
                  >> >> >
                  >> >> > With applicationObje ct.CommandBars( "Sample Toolbar")
                  >> >> > If lToolbarPos = msoBarTop Or lToolbarPos =[/color][/color]
                  >msoBarBottom[color=green][color=darkred]
                  >> >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" <jaimer@nvisi on-tech.com> wrote in message
                  >> >> >news:eqN0$MegD HA.1760@TK2MSFT NGP09.phx.gbl.. .
                  >> >> >> Now I am having a problem where the COM AddIn will not load at all![/color][/color]
                  >Is[color=green][color=darkred]
                  >> >> >there
                  >> >> >> a setting or something that Word has done to prevent it from[/color][/color]
                  >loading?[color=green][color=darkred]
                  >> >> >>
                  >> >> >> Jaime
                  >> >> >> "Peter Huang [MSFT]" <v-phuang@online.m icrosoft.com> wrote in[/color][/color]
                  >message[color=green][color=darkred]
                  >> >> >> news:3URrTTXgDH A.2272@cpmsftng xa06.phx.gbl...
                  >> >> >> > Hi Jaime,
                  >> >> >> >
                  >> >> >> > You may try to check if the Registry setting has been set. [using[/color]
                  >> the[color=darkred]
                  >> >> >> > regedit tool]
                  >> >> >> > The setting is usually under the Key
                  >> >> >> > HKEY_CURRENT_US ER\Software\VB and VBA Program Settings
                  >> >> >> > and
                  >> >> >> >
                  >> >HKEY_USERS\< S-1-5-21-2146773085-903363285-719344707-166692>\Softwar e\VB
                  >> >> >> and
                  >> >> >> > VBA Program Settings\AppTes t
                  >> >> >> > the <> section may be different from yours. You may search using[/color][/color]
                  >the[color=green][color=darkred]
                  >> >> >find
                  >> >> >> > function in the regedit.
                  >> >> >> >
                  >> >> >> > I suggest that you break the with-endwith section into four code[/color]
                  >> line[color=darkred]
                  >> >> to
                  >> >> >> > see which function cause the error.
                  >> >> >> > Since it seems the error you got is related with the File System,[/color][/color]
                  >do[color=green][color=darkred]
                  >> >> 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[/color][/color][/color]
                  no[color=blue][color=green][color=darkred]
                  >> >> >rights.
                  >> >> >> >
                  >> >> >> > --------------------
                  >> >> >> > >Content-Class: urn:content-classes:message
                  >> >> >> > >From: "Jaime Rios" <jaimer@nvisi on-tech.com>
                  >> >> >> > >Sender: "Jaime Rios" <jaimer@nvisi on-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: <a81901c3810a$b bd32960$a601280 a@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: AcOBCrvTw0D7D7R 6RiqyWJZyUpmpvA ==
                  >> >> >> > >Newsgroups: microsoft.publi c.dotnet.genera l
                  >> >> >> > >Path: cpmsftngxa06.ph x.gbl
                  >> >> >> > >Xref: cpmsftngxa06.ph x.gbl[/color][/color][/color]
                  microsoft.publi c.dotnet.genera l:109406[color=blue][color=green][color=darkred]
                  >> >> >> > >NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
                  >> >> >> > >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
                  >> >> >> > >
                  >> >> >> > >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 "OnConnecti on" function but it fails
                  >> >> >> > >with an error, "Run-time exception thrown :
                  >> >> >> > >System.IO.IOEx ception - Bad file name or number."
                  >> >> >> > >
                  >> >> >> > >With applicationObje ct.CommandBars( "SampleToolbar" )
                  >> >> >> > > .Left = CLng(GetSetting
                  >> >> >> > >("SampleToolba r", "General", "ToolbarLef t", 0))
                  >> >> >> > > .Top = CLng(GetSetting
                  >> >> >> > >("SampleToolba r", "General", "ToolbarTop ", 0))
                  >> >> >> > > .Position = CLng(GetSetting
                  >> >> >> > >("SampleToolba r", "General", "ToolbarPos ", CStr
                  >> >> >> > >(msoBarTop)) )
                  >> >> >> > > .Index = CLng(GetSetting
                  >> >> >> > >("SampleToolba r", "General", "ToolbarInd ex", 0))
                  >> >> >> > >End With
                  >> >> >> > >
                  >> >> >> > >Any help is appreciated! Thanks!
                  >> >> >> > >
                  >> >> >> > >Jaime Rios
                  >> >> >> > >
                  >> >> >> > >
                  >> >> >> > >
                  >> >> >> >
                  >> >> >>
                  >> >> >>
                  >> >> >
                  >> >> >
                  >> >> >
                  >> >>
                  >> >
                  >> >
                  >> >[/color]
                  >>[/color]
                  >
                  >
                  >[/color]

                  Comment

                  Working...