[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1846
  • Last Modified:

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
0
jbotts
Asked:
jbotts
  • 6
  • 4
  • 4
  • +2
1 Solution
 
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
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:

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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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 MVP, Access and Data Platform)Commented:
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
 
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
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"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 MVP, Access and Data Platform)Commented:
"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 MVP, Access and Data Platform)Commented:
"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

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 6
  • 4
  • 4
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now