2017-06-27 100 views
0

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

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

您是否尝试过这个问题https://stackoverflow.com/questions/579797/open-excel-file-for-reading-with-vba-without-display – Gowire

+0

'所以进度条窗口appear.'什么进度条窗口? –

+0

@Siddharth Rout,保存进度,打开进度(文件足够大,可以显示)。 – Ans

回答

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 
+0

它不工作;(绊倒开放它,只是认为,并认为... – Ans

+0

我编辑我的问题,包括您的代码。 – Ans