VBA - Opening a Word document. Document is minimized.

Using the following code in Access to open a Word document, the word document is minimized to the task bar. How do I get Word to display the document?
    Dim path As String
    Dim wo As Word.Application
    path = "C:\" & dir & "\Tutorial Instructions.doc"
    Set wo = CreateObject("Word.Application")
    wo.Visible = True
    wo.Documents.Open(path).Activate
jbottsAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Commented:


try this


dim wdpath,path

path = "C:\" & dir & "\Tutorial Instructions.doc"
wdpath = "WinWord.exe" & " " & Chr(34) & path & Chr(34)

Shell wdPath, vbMaximizedFocus


0
 
mbizupCommented:
Give this a try -

It has worked for me under earlier versions of Access/Windows as I recall:

    wo.Application.WindowState = wdWindowStateMinimize

But it doesnt seem to work with my current combination of Office 2010 and Windows 7.
0
 
danishaniCommented:
To activate the Word Instance, just use:

wo.Activate

instead of :
wo.Documents.Open(path).Activate

So the whole code will be:
  Dim path As String
    Dim wo As Word.Application
    path = "C:\" & dir & "\Tutorial Instructions.doc"
    Set wo = CreateObject("Word.Application")
    wo.Visible = True
    wo.Documents.Open(path)
    wo.Activate

Open in new window


Hope this helps,
Daniel

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:

What you posted (except for the one change) works for me on WinXP / A2003 and Win7 x64 / A2010:

    Dim path As String
    Dim wo As Word.Application
    ' path = "C:\" & dir & "\MyWord.doc"  ' error - Invalid procedure call or argument
    path = "C:\MyWord.doc"
    Set wo = CreateObject("Word.Application")
    wo.Visible = True
    wo.Documents.Open(path).Activate

    The Word doc opens in Normal focus.

You don't by chance have dual monitors, where the 2nd monitor is off ... and the doc is opening on the 2nd monitor, but showing minimized on the task bar ?

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
This works on WinXP / A2003.  However, it worked the first time on Win7 x64 / A2010, then I kept getting errors about ActiveX control on the With Word.Application.

    Dim path As String
    path = "C:\OhMyWord.doc"
    With Word.Application
        .Visible = True
        .Documents.Open(path).Activate
        .WindowState = wdWindowStateNormal  ' added this for fun
    End With

This also works on both systems:

    Dim path As String
    Dim wo As Word.Application
    path = "C:\OhMyWord.doc"
    Set wo = CreateObject("Word.Application")
    With wo
        .Visible = True
        .Documents.Open(path).Activate
        .WindowState = wdWindowStateNormal
    End With
    Set wo = Nothing
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
And this also works.


    Dim path As String
    Dim wo As Object ' Word.Application
    path = "C:\LinkedInMVP.doc"
    Set wo = CreateObject("Word.Application")
    With wo
        .Visible = True
        .Documents.Open(path).Activate
        .WindowState = wdWindowStateNormal
    End With
    Set wo = Nothing

 I don't think you then need a Reference to Word, but you lose intellisense.
0
 
mbizupCommented:
Typo in my first post http:#a36953378.  I meant to use

    wo.Application.WindowState = wdWindowStateMaximize '(not minimize)

I must have been tired last night.

Anyhow - it just didn't work for me under Office 2010/Windows 7 which I was using last night.  Regardless of that addition (or wdWindowStateNormal) , Word appeared minimized in the task bar, with Access in focus in the foreground.

It does work for me on the computer I'm using now (Office 2007/Windows XP Pro).

I seem to recall having similar issues with Outlook automation through Access.

0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"it just didn't work for me under Office 2010/Windows 7 which I was using last night. "
Odd that it does on mine.

mx
0
 
jbottsAuthor Commented:
danishani: I tried the
   wo.Documents.Open(path)
    wo.Activate
It did not make a difference.
0
 
jbottsAuthor Commented:
DatabaseMX: I failed to show that 'dir' is a string with part of the path in it. Use of "C:\MyWord.doc" resulted in the same problem. 'dir' was a poor choice for string name.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"It did not make a difference."
That is not necessary anyway.  Doing it on one line is more efficient and less code.

See the posts I made above ... all of which work.

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
"I failed to show that 'dir' is a string with part of the path in it. Use of "C:\MyWord.doc" resulted in the same problem. 'dir' was a poor choice for string name. "

Got it.  I just fully hard coded a path.

mx
0
 
danishaniCommented:
Try the following:
Dim oWord As Word.Application
' create a new instance
Set oWord = New Word.Application
' make it visible
oWord.Visible = True
' activate the document - Note: make it visible should normaly do the trick already
oWord.Documents.Open strPath
oWord.Activate
' release the object
Set oWord = Nothing

Open in new window


Hope this helps,
Daniel
0
 
Rey Obrero (Capricorn1)Commented:


jbotts,

did you try the code at http:#a36955304 ?


0
 
jbottsAuthor Commented:
capricorn1:
I did try the code at http:#a36955304. I worked very well and very fast. I am not that familiar with Shell commands. Still using VBA how do I close the openend WinWord.exe?
0
 
Rey Obrero (Capricorn1)Commented:
how do I close the openend WinWord.exe?  from VBA? no need to.

 
0
 
jbottsAuthor Commented:
Am I able to open multiple documents using the Shell command?
0
 
Rey Obrero (Capricorn1)Commented:
why not try it ...

if your original problem was resolved, close this thread and open another one for your other problems..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.