excelvbainternet-explorerms-wordminimized

Why do the application windows remain minimized after opening when called with vba?


I have this problem all the time with various applications when I open them via VBA. Internet Explorer, Word, Excel, etc., all open, even the document opens, but the window remains minimized on the taskbar and must be opened manually. I also have this problem on several computers, with different versions of Office. (Windows 10 pro, Office 2019 Pro and Office 365), same problem on all of them. Does anyone have a solution for this? Tanks

Code for Word (with MS-Access VBA):

Sub OpenDoc()

Dim WordApp As Object, WordDoc As String

WordDoc = "C:\Users\Me\Desktop\Document01.docx"

Set WordApp = CreateObject("Word.Application")
    WordApp.Visible = True
    WordApp.Documents.Open (WordDoc)

End Sub

Code for IE:

Sub openIE()

Dim oIE As InternetExplorer

Set oIE = New InternetExplorer

URL = xxx

With oIE
   .Visible = True
   .Navigate2 URL
   .Activate
    Do While .readyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
End With

'or

'With oIE
'   .Visible = True
'   .Navigate2 URL
'   .Activate
'End With
'
'    Do While IE.readyState <> READYSTATE_COMPLETE
'    DoEvents
'    Loop

End Sub

Solution

  • try this

    Sub OpenDoc()
    
    Dim WordApp As Object, WordDoc As String
    
    WordDoc = "C:\Users\Me\Desktop\Document01.docx"
    
    Set WordApp = CreateObject("Word.Application")
        WordApp.Visible = True
        WordApp.Documents.Open (WordDoc)
        WordApp.Activate
    End Sub