Excel VBA隐藏文件打开并保存窗口



i hava a acacros打开,编辑和保存文件。但这需要一些时间,因此出现了进度条窗口。我不知道如何摆脱它们。我尝试了:

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

但行不通。有建议吗?

编辑:这是我的代码:

我在这里尝试了建议的答案,但它不起作用(所有这些都放慢了,输出文件夹为空(。也许我做错了吗?

Sub iterateThroughFolder()
    '**SETTINGS**
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.StatusBar = "Starting..."
    '**VARIABLES**
    Dim folderPath As String
    folderPath = "Y:vbatest_reservestest_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:vbatest_reservesfilesrating_template.xls")
        'Set dataWorkbook = Workbooks.Open(folderPath & fileTitle)
        'NEW VARIANT:
        'Set resultWorkbook = app.Workbooks.Add("Y:vbatest_reservesfilesrating_template.xls")
       ' Set dataWorkbook = app.Workbooks.Add(folderPath & fileTitle)
       'NEXT NEW VARIANT (from this question's answer):
       Set resultWorkbook =app.Application.Workbooks.Open
         ("Y:vbatest_reservesfilesrating_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:vbatest_reservesoutput" + 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

相关内容

  • 没有找到相关文章

最新更新