2014-11-25 35 views
0

我正在为我的公司写一个excel vba脚本,并且在顺利运行时遇到了一些麻烦。为了使我的脚本能够做到这一点,我需要打开两个可在我公司的Intranet上使用的Excel文档。以下是我目前正在使用的代码:从互联网打开excel文档笨重

Sub checkForGrids() 


Dim IE As Object 
Dim link As String 

On Error Resume Next 




       Set groupGrid = Workbooks(Sheet2.Cells(3, 2).value) 


       If groupGrid Is Nothing Then 
        MsgBox ("The Service Area Grid is required for this tool to run. Attempting to open now.") 
        Set IE = CreateObject("InternetExplorer.Application") 
        link = Sheet2.Cells(3, 3) 
        With IE 
         .Visible = True 
         .Navigate link 
        End With 
       End If 

       Set groupGrid = Workbooks(Sheet2.Cells(4, 2).value) 

       If groupGrid Is Nothing Then 
        MsgBox ("The Service Area Grid is required for this tool to run. Attempting to open now.") 
        Set IE = CreateObject("InternetExplorer.Application") 
        link = Sheet2.Cells(4, 3) 
        With IE 
         .Visible = True 
         .Navigate link 
        End With 
       End If 





End Sub 

这只是正常,但你必须点击MSGBOX确定,单击打开,单击确定,并打开第二个文档之前等待。我的同事在弹出后立即点击第二个确定按钮,导致错误。

有没有更流畅的方法来完成这个?我希望他们不必点击“打开”,但我一直无法找到这样的方法。谢谢

+0

'Workbooks.Open Sheet2.Cells(3,3).Value'假设单元格有一个到工作簿的HTTP链接 – 2014-11-26 05:45:55

回答

1

您可以通过不使其可见的方式静默运行IE,停止屏幕更新并使用Application.StatusBar方法通知用户正在发生的事情。

或者,您可以创建一个小的用户窗体,在非模态状态下弹出,然后在需要的代码运行时隐藏。