【问题标题】:refresh pivot table in multiple active workbooks at once一次刷新多个活动工作簿中的数据透视表
【发布时间】:2014-09-26 14:52:47
【问题描述】:

我需要定期从我们的 SQL 数据库中的不同工作簿刷新多个数据透视表。

最简单的方法是什么?一次刷新不同工作簿中的数据透视表?如果是vba格式就可以了。

【问题讨论】:

  • Workbook ObjectRefreshAll 方法,用于刷新所有连接、数据透视表、公式等。VBA 形式 Workbooks("Workbookname").RefreshAll

标签: excel vba


【解决方案1】:

ok,下面的代码会询问你excel文件所在的文件夹路径(需要刷新)

Source :

Sub LoopAllExcelFilesInFolder()

'PURPOSE: To loop through all Excel files in a user specified folder and perform a set task on them
'SOURCE: www.TheSpreadsheetGuru.com

Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog

'Optimize Macro Speed
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  Application.Calculation = xlCalculationManual

'Retrieve Target Folder Path From User
  Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)

    With FldrPicker
      .Title = "Select A Target Folder"
      .AllowMultiSelect = False
        If .Show <> -1 Then GoTo NextCode
        myPath = .SelectedItems(1) & "\"
    End With

'In Case of Cancel
NextCode:
  myPath = myPath
  If myPath = "" Then Exit Sub

'Target File Extension (must include wildcard "*")
  myExtension = "*.xls"

'Target Path with Ending Extention
  myFile = Dir(myPath & myExtension)

'Loop through each Excel file in folder
  Do While myFile <> ""
    'Set variable equal to opened workbook
      Set wb = Workbooks.Open(Filename:=myPath & myFile)

    'Refresh the workbook
      wb.refreshall

    'Save and Close Workbook
      wb.Close SaveChanges:=True

    'Get next file name
      myFile = Dir
  Loop

'Message Box when tasks are completed
  MsgBox "Task Complete!"

'Reset Macro Optimization Settings
  Application.ScreenUpdating = True
  Application.EnableEvents = True
  Application.Calculation = xlCalculationAutomatic

End Sub

【讨论】:

    【解决方案2】:

    太棒了!它工作..我现在需要做的就是观察刷新后的结果..如果它在我需要的输出方面工作 100%..

    【讨论】:

    • 请使用您问题上的编辑链接添加其他信息。 “发布答案”按钮应仅用于问题的完整答案。
    • 对不起,我只是个初学者
    猜你喜欢
    • 2014-07-04
    • 2017-11-22
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    • 2010-09-09
    • 1970-01-01
    相关资源
    最近更新 更多