Quitting "Word.Application" Help Please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Roys

    #1

    Quitting "Word.Application" Help Please

    Hi

    Im doing something wrong in quitting the Word.Applicatio n in my VB program.
    I have

    General Declarations
    Dim AppWord As Word.Applicatio n

    Form_Load()
    Set AppWord = CreateObject("W ord.Application ")

    cmdExit_Click()
    AppWord.Quit
    Set AppWord = Nothing
    Unload Me

    When I click Exit to end my program Winword.exe is still running as a
    process listed in my Task Manager. Not only is it listed, but the process is
    taking up 100% of my CPU usage.
    How do I end the Word.Applicatio n correctly ???

    Thanks
    Trevor.


  • Stephane Richard

    #2
    Re: Quitting "Word.Appl ication" Help Please

    The first thing I see is that you are using a mix of Early and Late binding
    to create your object.

    This is your code as it stands:[color=blue]
    > General Declarations
    > Dim AppWord As Word.Applicatio n
    >
    > Form_Load()
    > Set AppWord = CreateObject("W ord.Application ")
    >
    > cmdExit_Click()
    > AppWord.Quit
    > Set AppWord = Nothing
    > Unload Me[/color]

    In early binding mode it should be:[color=blue]
    > General Declarations
    > Dim AppWord As Word.Applicatio n
    >
    > Form_Load()
    > Set AppWord = New Word.Applicatio n
    >[/color]

    In Late Binding mode (using createobject()) it should be:[color=blue]
    > General Declarations
    > Dim AppWord As Object
    >
    > Form_Load()
    > Set AppWord = CreateObject("W ord.Application ")
    >[/color]
    Try the same code to end your word application object as you have with one
    of these two declarations (early or late binding). and see if it still
    causes a problem.

    --
    Stéphane Richard



    "The Roys" <trevr62@hotmai l.com> wrote in message
    news:VKqjb.1527 73$bo1.81653@ne ws-server.bigpond. net.au...[color=blue]
    > Hi
    >
    > Im doing something wrong in quitting the Word.Applicatio n in my VB[/color]
    program.[color=blue]
    > I have
    >
    > General Declarations
    > Dim AppWord As Word.Applicatio n
    >
    > Form_Load()
    > Set AppWord = CreateObject("W ord.Application ")
    >
    > cmdExit_Click()
    > AppWord.Quit
    > Set AppWord = Nothing
    > Unload Me
    >
    > When I click Exit to end my program Winword.exe is still running as a
    > process listed in my Task Manager. Not only is it listed, but the process[/color]
    is[color=blue]
    > taking up 100% of my CPU usage.
    > How do I end the Word.Applicatio n correctly ???
    >
    > Thanks
    > Trevor.
    >
    >[/color]


    Comment

    • The Roys

      #3
      Re: Quitting &quot;Word.Appl ication&quot; Help Please

      Thanks for your reply, but either way makes no difference. Before exiting,
      and while program is dormant the process in the Task Manager (Winword.exe)
      does not take up any CPU usage. But as soon as I run the Exit code the CPU
      usage goes to 100% and the process is still in the Task Manager.
      Every time I run the program a new Winword.exe process begins.

      Any ideas ??


      "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
      news:QEujb.1938 6$0I6.4987@nwrd ny03.gnilink.ne t...[color=blue]
      > The first thing I see is that you are using a mix of Early and Late[/color]
      binding[color=blue]
      > to create your object.
      >
      > This is your code as it stands:[color=green]
      > > General Declarations
      > > Dim AppWord As Word.Applicatio n
      > >
      > > Form_Load()
      > > Set AppWord = CreateObject("W ord.Application ")
      > >
      > > cmdExit_Click()
      > > AppWord.Quit
      > > Set AppWord = Nothing
      > > Unload Me[/color]
      >
      > In early binding mode it should be:[color=green]
      > > General Declarations
      > > Dim AppWord As Word.Applicatio n
      > >
      > > Form_Load()
      > > Set AppWord = New Word.Applicatio n
      > >[/color]
      >
      > In Late Binding mode (using createobject()) it should be:[color=green]
      > > General Declarations
      > > Dim AppWord As Object
      > >
      > > Form_Load()
      > > Set AppWord = CreateObject("W ord.Application ")
      > >[/color]
      > Try the same code to end your word application object as you have with one
      > of these two declarations (early or late binding). and see if it still
      > causes a problem.
      >
      > --
      > Stéphane Richard
      >
      >
      >
      > "The Roys" <trevr62@hotmai l.com> wrote in message
      > news:VKqjb.1527 73$bo1.81653@ne ws-server.bigpond. net.au...[color=green]
      > > Hi
      > >
      > > Im doing something wrong in quitting the Word.Applicatio n in my VB[/color]
      > program.[color=green]
      > > I have
      > >
      > > General Declarations
      > > Dim AppWord As Word.Applicatio n
      > >
      > > Form_Load()
      > > Set AppWord = CreateObject("W ord.Application ")
      > >
      > > cmdExit_Click()
      > > AppWord.Quit
      > > Set AppWord = Nothing
      > > Unload Me
      > >
      > > When I click Exit to end my program Winword.exe is still running as a
      > > process listed in my Task Manager. Not only is it listed, but the[/color][/color]
      process[color=blue]
      > is[color=green]
      > > taking up 100% of my CPU usage.
      > > How do I end the Word.Applicatio n correctly ???
      > >
      > > Thanks
      > > Trevor.
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Norman Yuan

        #4
        Re: Quitting &quot;Word.Appl ication&quot; Help Please

        Just my guess:

        Is there some code create a varable (probably at form level) that references
        object in Word.Applicatio n somewhere between Foam_Load and cmdExit_Click,
        which is still alive (not set to Nothing)?

        If you simply try to start Word.Applicatio n and close it in the same
        procedure, like below, I'll bet Word.Applicatio n would quit cleanly:

        Private Sub cmdTest_Click()

        Dim AppWord As Word.Applicatio n

        Set AppWord=New Word.Applicatio n 'You can use CreateObject() if you
        wish

        MsgBox "Word launched"

        AppWord.Quit;
        '.............. ......
        End Sub

        If Word.Applicatio n quits correctly here, then find some code in your
        project that has something to do with AppWord before cmdExit_Click

        "The Roys" <trevr62@hotmai l.com> wrote in message
        news:oVxjb.1534 83$bo1.20747@ne ws-server.bigpond. net.au...[color=blue]
        > Thanks for your reply, but either way makes no difference. Before exiting,
        > and while program is dormant the process in the Task Manager (Winword.exe)
        > does not take up any CPU usage. But as soon as I run the Exit code the CPU
        > usage goes to 100% and the process is still in the Task Manager.
        > Every time I run the program a new Winword.exe process begins.
        >
        > Any ideas ??
        >
        >
        > "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
        > news:QEujb.1938 6$0I6.4987@nwrd ny03.gnilink.ne t...[color=green]
        > > The first thing I see is that you are using a mix of Early and Late[/color]
        > binding[color=green]
        > > to create your object.
        > >
        > > This is your code as it stands:[color=darkred]
        > > > General Declarations
        > > > Dim AppWord As Word.Applicatio n
        > > >
        > > > Form_Load()
        > > > Set AppWord = CreateObject("W ord.Application ")
        > > >
        > > > cmdExit_Click()
        > > > AppWord.Quit
        > > > Set AppWord = Nothing
        > > > Unload Me[/color]
        > >
        > > In early binding mode it should be:[color=darkred]
        > > > General Declarations
        > > > Dim AppWord As Word.Applicatio n
        > > >
        > > > Form_Load()
        > > > Set AppWord = New Word.Applicatio n
        > > >[/color]
        > >
        > > In Late Binding mode (using createobject()) it should be:[color=darkred]
        > > > General Declarations
        > > > Dim AppWord As Object
        > > >
        > > > Form_Load()
        > > > Set AppWord = CreateObject("W ord.Application ")
        > > >[/color]
        > > Try the same code to end your word application object as you have with[/color][/color]
        one[color=blue][color=green]
        > > of these two declarations (early or late binding). and see if it still
        > > causes a problem.
        > >
        > > --
        > > Stéphane Richard
        > >
        > >
        > >
        > > "The Roys" <trevr62@hotmai l.com> wrote in message
        > > news:VKqjb.1527 73$bo1.81653@ne ws-server.bigpond. net.au...[color=darkred]
        > > > Hi
        > > >
        > > > Im doing something wrong in quitting the Word.Applicatio n in my VB[/color]
        > > program.[color=darkred]
        > > > I have
        > > >
        > > > General Declarations
        > > > Dim AppWord As Word.Applicatio n
        > > >
        > > > Form_Load()
        > > > Set AppWord = CreateObject("W ord.Application ")
        > > >
        > > > cmdExit_Click()
        > > > AppWord.Quit
        > > > Set AppWord = Nothing
        > > > Unload Me
        > > >
        > > > When I click Exit to end my program Winword.exe is still running as a
        > > > process listed in my Task Manager. Not only is it listed, but the[/color][/color]
        > process[color=green]
        > > is[color=darkred]
        > > > taking up 100% of my CPU usage.
        > > > How do I end the Word.Applicatio n correctly ???
        > > >
        > > > Thanks
        > > > Trevor.
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • The Roys

          #5
          Re: Quitting &quot;Word.Appl ication&quot; Help Please

          Yes Norman, You are absolutely correct. I am using the the spell checker in
          word. If the spell checker is not used then the Winword.exe process does
          close correctly.
          Ok, now how do I close it down correctly if I do use the spell checker. The
          spell checker code I have is:
          If (AppWord.CheckS pelling(searchW ord) Then
          'This is a word -
          count = count + 1
          End If
          This is the only code in my program which accesses Winword.
          Do I also need to close the CheckSpelling process ???



          "Norman Yuan" <normanyuan@Rem oveThis.shaw.ca > wrote in message
          news:oMCjb.1094 82$pl3.80542@pd 7tw3no...[color=blue]
          > Just my guess:
          >
          > Is there some code create a varable (probably at form level) that[/color]
          references[color=blue]
          > object in Word.Applicatio n somewhere between Foam_Load and cmdExit_Click,
          > which is still alive (not set to Nothing)?
          >
          > If you simply try to start Word.Applicatio n and close it in the same
          > procedure, like below, I'll bet Word.Applicatio n would quit cleanly:
          >
          > Private Sub cmdTest_Click()
          >
          > Dim AppWord As Word.Applicatio n
          >
          > Set AppWord=New Word.Applicatio n 'You can use CreateObject() if you
          > wish
          >
          > MsgBox "Word launched"
          >
          > AppWord.Quit;
          > '.............. ......
          > End Sub
          >
          > If Word.Applicatio n quits correctly here, then find some code in your
          > project that has something to do with AppWord before cmdExit_Click
          >
          > "The Roys" <trevr62@hotmai l.com> wrote in message
          > news:oVxjb.1534 83$bo1.20747@ne ws-server.bigpond. net.au...[color=green]
          > > Thanks for your reply, but either way makes no difference. Before[/color][/color]
          exiting,[color=blue][color=green]
          > > and while program is dormant the process in the Task Manager[/color][/color]
          (Winword.exe)[color=blue][color=green]
          > > does not take up any CPU usage. But as soon as I run the Exit code the[/color][/color]
          CPU[color=blue][color=green]
          > > usage goes to 100% and the process is still in the Task Manager.
          > > Every time I run the program a new Winword.exe process begins.
          > >
          > > Any ideas ??
          > >
          > >
          > > "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
          > > news:QEujb.1938 6$0I6.4987@nwrd ny03.gnilink.ne t...[color=darkred]
          > > > The first thing I see is that you are using a mix of Early and Late[/color]
          > > binding[color=darkred]
          > > > to create your object.
          > > >
          > > > This is your code as it stands:
          > > > > General Declarations
          > > > > Dim AppWord As Word.Applicatio n
          > > > >
          > > > > Form_Load()
          > > > > Set AppWord = CreateObject("W ord.Application ")
          > > > >
          > > > > cmdExit_Click()
          > > > > AppWord.Quit
          > > > > Set AppWord = Nothing
          > > > > Unload Me
          > > >
          > > > In early binding mode it should be:
          > > > > General Declarations
          > > > > Dim AppWord As Word.Applicatio n
          > > > >
          > > > > Form_Load()
          > > > > Set AppWord = New Word.Applicatio n
          > > > >
          > > >
          > > > In Late Binding mode (using createobject()) it should be:
          > > > > General Declarations
          > > > > Dim AppWord As Object
          > > > >
          > > > > Form_Load()
          > > > > Set AppWord = CreateObject("W ord.Application ")
          > > > >
          > > > Try the same code to end your word application object as you have with[/color][/color]
          > one[color=green][color=darkred]
          > > > of these two declarations (early or late binding). and see if it[/color][/color][/color]
          still[color=blue][color=green][color=darkred]
          > > > causes a problem.
          > > >
          > > > --
          > > > Stéphane Richard
          > > >
          > > >
          > > >
          > > > "The Roys" <trevr62@hotmai l.com> wrote in message
          > > > news:VKqjb.1527 73$bo1.81653@ne ws-server.bigpond. net.au...
          > > > > Hi
          > > > >
          > > > > Im doing something wrong in quitting the Word.Applicatio n in my VB
          > > > program.
          > > > > I have
          > > > >
          > > > > General Declarations
          > > > > Dim AppWord As Word.Applicatio n
          > > > >
          > > > > Form_Load()
          > > > > Set AppWord = CreateObject("W ord.Application ")
          > > > >
          > > > > cmdExit_Click()
          > > > > AppWord.Quit
          > > > > Set AppWord = Nothing
          > > > > Unload Me
          > > > >
          > > > > When I click Exit to end my program Winword.exe is still running as[/color][/color][/color]
          a[color=blue][color=green][color=darkred]
          > > > > process listed in my Task Manager. Not only is it listed, but the[/color]
          > > process[color=darkred]
          > > > is
          > > > > taking up 100% of my CPU usage.
          > > > > How do I end the Word.Applicatio n correctly ???
          > > > >
          > > > > Thanks
          > > > > Trevor.
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • The Roys

            #6
            Re: Quitting &quot;Word.Appl ication&quot; Help Please

            I have just solved my problem.
            I have accessed the Spell Checker via Excel rather than Winword, and the
            process closes correctly.
            Is this a bug with Winword, or a bug in my Winword, don't know, don't really
            need to know now.

            Thanks for your help guys.



            "The Roys" <trevr62@hotmai l.com> wrote in message
            news:AtEjb.1536 26$bo1.87142@ne ws-server.bigpond. net.au...[color=blue]
            > Yes Norman, You are absolutely correct. I am using the the spell checker[/color]
            in[color=blue]
            > word. If the spell checker is not used then the Winword.exe process does
            > close correctly.
            > Ok, now how do I close it down correctly if I do use the spell checker.[/color]
            The[color=blue]
            > spell checker code I have is:
            > If (AppWord.CheckS pelling(searchW ord) Then
            > 'This is a word -
            > count = count + 1
            > End If
            > This is the only code in my program which accesses Winword.
            > Do I also need to close the CheckSpelling process ???
            >
            >
            >
            > "Norman Yuan" <normanyuan@Rem oveThis.shaw.ca > wrote in message
            > news:oMCjb.1094 82$pl3.80542@pd 7tw3no...[color=green]
            > > Just my guess:
            > >
            > > Is there some code create a varable (probably at form level) that[/color]
            > references[color=green]
            > > object in Word.Applicatio n somewhere between Foam_Load and[/color][/color]
            cmdExit_Click,[color=blue][color=green]
            > > which is still alive (not set to Nothing)?
            > >
            > > If you simply try to start Word.Applicatio n and close it in the same
            > > procedure, like below, I'll bet Word.Applicatio n would quit cleanly:
            > >
            > > Private Sub cmdTest_Click()
            > >
            > > Dim AppWord As Word.Applicatio n
            > >
            > > Set AppWord=New Word.Applicatio n 'You can use CreateObject() if[/color][/color]
            you[color=blue][color=green]
            > > wish
            > >
            > > MsgBox "Word launched"
            > >
            > > AppWord.Quit;
            > > '.............. ......
            > > End Sub
            > >
            > > If Word.Applicatio n quits correctly here, then find some code in your
            > > project that has something to do with AppWord before cmdExit_Click
            > >
            > > "The Roys" <trevr62@hotmai l.com> wrote in message
            > > news:oVxjb.1534 83$bo1.20747@ne ws-server.bigpond. net.au...[color=darkred]
            > > > Thanks for your reply, but either way makes no difference. Before[/color][/color]
            > exiting,[color=green][color=darkred]
            > > > and while program is dormant the process in the Task Manager[/color][/color]
            > (Winword.exe)[color=green][color=darkred]
            > > > does not take up any CPU usage. But as soon as I run the Exit code the[/color][/color]
            > CPU[color=green][color=darkred]
            > > > usage goes to 100% and the process is still in the Task Manager.
            > > > Every time I run the program a new Winword.exe process begins.
            > > >
            > > > Any ideas ??
            > > >
            > > >
            > > > "Stephane Richard" <stephane.richa rd@verizon.net> wrote in message
            > > > news:QEujb.1938 6$0I6.4987@nwrd ny03.gnilink.ne t...
            > > > > The first thing I see is that you are using a mix of Early and Late
            > > > binding
            > > > > to create your object.
            > > > >
            > > > > This is your code as it stands:
            > > > > > General Declarations
            > > > > > Dim AppWord As Word.Applicatio n
            > > > > >
            > > > > > Form_Load()
            > > > > > Set AppWord = CreateObject("W ord.Application ")
            > > > > >
            > > > > > cmdExit_Click()
            > > > > > AppWord.Quit
            > > > > > Set AppWord = Nothing
            > > > > > Unload Me
            > > > >
            > > > > In early binding mode it should be:
            > > > > > General Declarations
            > > > > > Dim AppWord As Word.Applicatio n
            > > > > >
            > > > > > Form_Load()
            > > > > > Set AppWord = New Word.Applicatio n
            > > > > >
            > > > >
            > > > > In Late Binding mode (using createobject()) it should be:
            > > > > > General Declarations
            > > > > > Dim AppWord As Object
            > > > > >
            > > > > > Form_Load()
            > > > > > Set AppWord = CreateObject("W ord.Application ")
            > > > > >
            > > > > Try the same code to end your word application object as you have[/color][/color][/color]
            with[color=blue][color=green]
            > > one[color=darkred]
            > > > > of these two declarations (early or late binding). and see if it[/color][/color]
            > still[color=green][color=darkred]
            > > > > causes a problem.
            > > > >
            > > > > --
            > > > > Stéphane Richard
            > > > >
            > > > >
            > > > >
            > > > > "The Roys" <trevr62@hotmai l.com> wrote in message
            > > > > news:VKqjb.1527 73$bo1.81653@ne ws-server.bigpond. net.au...
            > > > > > Hi
            > > > > >
            > > > > > Im doing something wrong in quitting the Word.Applicatio n in my VB
            > > > > program.
            > > > > > I have
            > > > > >
            > > > > > General Declarations
            > > > > > Dim AppWord As Word.Applicatio n
            > > > > >
            > > > > > Form_Load()
            > > > > > Set AppWord = CreateObject("W ord.Application ")
            > > > > >
            > > > > > cmdExit_Click()
            > > > > > AppWord.Quit
            > > > > > Set AppWord = Nothing
            > > > > > Unload Me
            > > > > >
            > > > > > When I click Exit to end my program Winword.exe is still running[/color][/color][/color]
            as[color=blue]
            > a[color=green][color=darkred]
            > > > > > process listed in my Task Manager. Not only is it listed, but the
            > > > process
            > > > > is
            > > > > > taking up 100% of my CPU usage.
            > > > > > How do I end the Word.Applicatio n correctly ???
            > > > > >
            > > > > > Thanks
            > > > > > Trevor.
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...