我有一个打开,编辑和保存文件的宏。但这需要一些时间,因此会出现进度条窗口。我不知道如何摆脱它们。我试过了:
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.DisplayAlerts = False
但它不起作用。有什么建议吗?
编辑:这是我的代码:
我尝试了建议的答案here,但它不起作用(它只是减速并且输出文件夹为空)。也许我这样做是错的?
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
答案 0 :(得分:1)
这里有一些你可以尝试的代码......它启动一个隐藏的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