简体   繁体   English

在Excel 2010 VBA中刷新数据连接

[英]Refreshing Data Connections in Excel 2010 VBA

So I have all of my VBA code down and it seems to be right, but it just is not refreshing the workbooks. 因此,我把所有的VBA代码都记下来了,这似乎是正确的,但这只是没有刷新工作簿。 The only thing that I can think of is when I open up the sheets I have to enable editting, so would I need to add something to my code? 我唯一能想到的就是打开工作表才能启用编辑功能,因此我需要在代码中添加一些内容吗?

Edit: I am running this through a VBScript 编辑:我正在通过VBScript运行

Public wb As Workbook

Sub executeUpdate()
    `some code
     openBook path & testArray(i) & ext, True
     saveBookAs path & testArray(i)
End Sub

Sub openBook(ByVal fileName As String, ByVal refresh As Boolean)

    Set wb = Workbooks.Open(fileName, 0, False)

    If refresh = True Then
        wb.RefreshAll
    End If
End Sub

Sub saveBookAs(ByVal fName As String)
    wb.SaveAs fileName:=fName & "_posReport.xlsx"
End Sub

I found this code over here : 我在这里找到了这段代码:

If Application.ProtectedViewWindows.Count > 0 Then
    Application.ActiveProtectedViewWindow.Edit
End If

Have not tested it, but maybe it works for you. 尚未测试过,但也许对您有用。

-- Quote: -Quote:

code will bypass the need for the user to select the "Enable Editing" button on the message bar below the ribbon. 代码无需用户选择功能区下方消息栏上的“启用编辑”按钮。 One additional note [...] the code will error if the workbook isn't in "ProtectedView". 还有一点需要注意的是,如果工作簿不在“ ProtectedView”中,则代码将出错。 So to avoid this the following code will only enable editing if the workbook has "ProtectedView" enabled. 因此,为避免这种情况,下面的代码仅在工作簿启用了“ ProtectedView”的情况下才启用编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM