Excel vba隐藏文件打开和文件保存窗口

我有一个打开,编辑和保存文件的macros。 但是这需要一些时间,因此进度条窗口出现。 我不知道如何摆脱它们。 我试过了:

Application.ScreenUpdating = False Application.DisplayStatusBar = False Application.DisplayAlerts = False 

但它不起作用。 有什么build议?

编辑 :这是我的代码:

我试着在这里build议的答案,但它不起作用(这一切只是减慢,输出文件夹是空的)。 也许我做错了?

 Sub iterateThroughFolder() '**SETTINGS** Application.ScreenUpdating = False Application.DisplayStatusBar = False Application.StatusBar = "Starting..." '**VARIABLES** Dim folderPath As String folderPath = "Y:\vba\test_reserves\test_data\" '**INVISIBLE APPLICATION** <---- the part from other answer ' Dim app As New Excel.Application Dim app As Object Set app = CreateObject("Excel.Application") app.Visible = False '**LOOPING THROUGH THE FOLDER** fileTitle = Dir(folderPath & "*.xl??") Do While fileTitle <> "" 'SETTINGS Application.DisplayAlerts = False Application.StatusBar = fileTitle + "pending: " 'OPENING FILES Dim resultWorkbook As Workbook Dim dataWorkbook As Workbook 'OLD VARIANT: 'Set resultWorkbook = 'Workbooks.Open("Y:\vba\test_reserves\files\rating_template.xls") 'Set dataWorkbook = Workbooks.Open(folderPath & fileTitle) 'NEW VARIANT: 'Set resultWorkbook = app.Workbooks.Add("Y:\vba\test_reserves\files\rating_template.xls") ' Set dataWorkbook = app.Workbooks.Add(folderPath & fileTitle) 'NEXT NEW VARIANT (from this question's answer): Set resultWorkbook =app.Application.Workbooks.Open ("Y:\vba\test_reserves\files\rating_template.xls ") Set dataWorkbook = app.Application.Workbooks.Open(folderPath & fileTitle) 'REFRESHING CONNECTIONS (?) Dim cn As WorkbookConnection For Each cn In resultWorkbook.Connections cn.Refresh Next 'GETTING THE NAME AND PUTTING IT IN "A1" cell of "B1" list Application.StatusBar = Application.StatusBar + "Getting the state name" Dim stateName As String stateName = dataWorkbook.Worksheets("ðàçäåë 1").Cells(5, 4).Value resultWorkbook.Worksheets("B1").Cells(1, 1).Value = stateName 'SAVING AND CLOSING Application.StatusBar = Application.StatusBar + "Saving and closing new rating file" resultWorkbook.SaveAs Filename:="Y:\vba\test_reserves\output\" + stateName resultWorkbook.Close dataWorkbook.Close Application.DisplayAlerts = True 'NEXT FILE Application.StatusBar = Application.StatusBar + "Getting next data file" fileTitle = Dir() Loop '**CLEANING THE APP** <--- from another answer, added it, so it doesn't 'work now app.Quit End Sub 

这里有一些代码你可以尝试…它启动一个隐藏的Excel应用程序并打开一个工作簿。 您可以使用WB对象使用此工作簿。

但是,如果操作需要时间(小时玻璃或旋转光标),您仍然会等待鼠标图标。

 Dim ExcelApp As Object Dim WB As Workbook Set ExcelApp = CreateObject("Excel.Application") Set WB = ExcelApp.Application.Workbooks.Open("myfile.xlsx") WB.DoYourStuffWithTheWorkbook WB.Save WB.Close