0

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
Jasco
  • 225
  • 3
  • 8

1 Answers1

2

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
virxen
  • 408
  • 4
  • 12
  • 4
    Any explanation as to why this might solve the problem? – QHarr Jun 13 '21 at 03:05
  • @virxen Yes :-) It works for me! With **WordApp.Activate** application window now pops up from the task bar after loading. THANKS! – Jasco Jun 13 '21 at 09:08
  • No...was probably just coincidence! At the same URL and under the same conditions: sometimes the window opens, sometimes (mostly at the beginning) it stays in the taskbar. **.activate** has not really helped, Thanks anyway – Jasco Jun 18 '21 at 18:40
  • 1
    for me works all the time.Maybe you are doing something else in your code that prevents it from happen. – virxen Jun 18 '21 at 19:04
  • I open ACCESS, click on a button in the form to open a link with IE (or a document with WORD). Always the same button and the same code. The first few times IE/WORD stay minimized in the taskbar. I have to open the window manually. Sometime after the nth repetition (without any parameters or conditions having changed) the same button click causes IE to open on its own. The same thing happens with WORD. I have used .activate, nothing has changed! – Jasco Jun 19 '21 at 08:55
  • I have just added the code for IE above. What in this code content could be causing the problem? – Jasco Jun 19 '21 at 09:06
  • 1
    try this:create a new access file with a button to open word and ie with the above code.just this nothing else.if it works then something else in the code has issues – virxen Jun 19 '21 at 10:29
  • Same! Maybe Access ist the problem....at the beginning, when I start access, it is always random whether the window opens or not, usually not, then after a few times it always opens. Have also turned off all plugins etc. in IE, URLs have no problematic content, it's really strange! Thanks for the efforts. – Jasco Jun 19 '21 at 11:22
  • try AppActivate Dir(WordDoc) instead of WordApp.Activate to see if it helps – virxen Jun 19 '21 at 11:33