How to keep word document open when it pops up?
In VB application I will pop up Work document through the reference "Word.Application".
The problem is after the document pops up it immediately closes, which function
does keep it open for reading? Thanks!
[214 byte] By [
Ken] at [2007-11-10 12:20:04]

# 1 Re: How to keep word document open when it pops up?
WordDocumentName.Visible = True
"Ken" <kzhao@lighthouse.org> wrote:
>
>In VB application I will pop up Work document through the reference "Word.Application".
>The problem is after the document pops up it immediately closes, which function
>does keep it open for reading? Thanks!
Ian at 2007-11-11 18:10:43 >

# 2 Re: How to keep word document open when it pops up?
On 18 Jul 2002 06:56:46 -0700, "Ken" <kzhao@lighthouse.org> wrote:
In VB application I will pop up Work document through the reference "Word.Application".
The problem is after the document pops up it immediately closes, which function
does keep it open for reading? Thanks!
It sounds like your object variable is going out of scope and as a result is being destroyed. You
might want to post your code so we can see what you are doing.
If you don't need to control Word and you're simply opening a document file you can also use the
ShellExecute API function call:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q170918
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
# 3 Re: How to keep word document open when it pops up?
Paul Clement <UseAdddressAtEndofMessage@swspectrum.com> wrote:
>On 18 Jul 2002 06:56:46 -0700, "Ken" <kzhao@lighthouse.org> wrote:
>
>
> In VB application I will pop up Work document through the reference "Word.Application".
> The problem is after the document pops up it immediately closes, which
function
> does keep it open for reading? Thanks!
>
>It sounds like your object variable is going out of scope and as a result
is being destroyed.
>You
>might want to post your code so we can see what you are doing.
>
>If you don't need to control Word and you're simply opening a document file
you can
>also use the
>ShellExecute API function call:
>
>http://support.microsoft.com/default.aspx?scid=kb;EN-US;q170918
>
>
>Paul ~~~ pclement@ameritech.net
>Microsoft MVP (Visual Basic)
ken at 2007-11-11 18:12:41 >

# 4 Re: How to keep word document open when it pops up?
Paul,
Thanks! The codes in one Button click event is following:
Dim doc As Word.Application
Set doc = New Word.Application
With doc
.Application.Documents.Open App.Path & "\" & Test & ".DOC"
.Application.Visible = True
.Application.WindowState = wdWindowStateMaximize
.Application.Activate
End With
Set doc = Nothing
Paul Clement <UseAdddressAtEndofMessage@swspectrum.com> wrote:
>On 18 Jul 2002 06:56:46 -0700, "Ken" <kzhao@lighthouse.org> wrote:
>
>
> In VB application I will pop up Work document through the reference "Word.Application".
> The problem is after the document pops up it immediately closes, which
function
> does keep it open for reading? Thanks!
>
>It sounds like your object variable is going out of scope and as a result
is being destroyed.
>You
>might want to post your code so we can see what you are doing.
>
>If you don't need to control Word and you're simply opening a document file
you can
>also use the
>ShellExecute API function call:
>
>http://support.microsoft.com/default.aspx?scid=kb;EN-US;q170918
>
>
>Paul ~~~ pclement@ameritech.net
>Microsoft MVP (Visual Basic)
Ken at 2007-11-11 18:13:45 >

# 5 Re: How to keep word document open when it pops up?
On 19 Jul 2002 07:42:14 -0700, "Ken" <kzhao@lighthouse.org> wrote:
Paul,
Thanks! The codes in one Button click event is following:
Dim doc As Word.Application
Set doc = New Word.Application
With doc
.Application.Documents.Open App.Path & "\" & Test & ".DOC"
.Application.Visible = True
.Application.WindowState = wdWindowStateMaximize
.Application.Activate
End With
Set doc = Nothing
I see two potential problems. First, you're setting doc equal to Nothing which is essentially
destroying the object variable. Second the doc variable is defined in the event which means that as
soon as the event terminates all variables declared within the event (locally) are destroyed.
To solve this problem I would declare the doc variable at the Form level (outside of any functions,
subs, or events at the top of the Form code module). You can leave the rest of the code as is (but
remove the line that sets doc = Nothing).
Paul ~~~ pclement@ameritech.net
Microsoft MVP (Visual Basic)
