【问题标题】:Why do the application windows remain minimized after opening when called with vba?为什么使用vba调用时应用程序窗口在打开后保持最小化?
【发布时间】:2021-06-13 00:02:38
【问题描述】:

当我通过 VBA 打开各种应用程序时,我总是遇到这个问题。 Internet Explorer、Word、Excel 等都打开了,甚至文档也打开了,但窗口在任务栏上保持最小化,必须手动打开。我在几台电脑上也有这个问题,使用不同版本的 Office。 (Windows 10 专业版、Office 2019 专业版和 Office 365),所有这些都存在同样的问题。有人对此有解决方案吗?坦克

Word 代码(使用 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

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

【问题讨论】:

  • 您的测试代码可以按照您的要求运行。

标签: excel vba internet-explorer ms-word minimized


【解决方案1】:

试试这个

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 是的 :-) 它对我有用! WordApp.Activate 应用程序窗口现在会在加载后从任务栏中弹出。谢谢!
  • 不...可能只是巧合!在相同的 URL 和相同的条件下:有时窗口打开,有时(主要是在开始时)它停留在任务栏中。 .activate 没有真正的帮助,还是谢谢
  • 对我来说一直有效。也许你在代码中做了其他事情来阻止它发生。
  • 试试这个:创建一个新的访问文件,用一个按钮打开单词,即使用上面的代码。只是这个没有别的。如果它有效,那么代码中的其他东西有问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多