2014-06-18 77 views
0

我有以下腳本:價值得到保存

Set fso = CreateObject("Scripting.FileSystemObject") 
Set xl = CreateObject("Excel.Application") 
xl.Visible = True 'set to False for production 
Set wb = xl.Workbooks.Open("C:\XXXSample_Data.xlsx") 'xl.Workbooks.Open(f.Path) 
Set ws = wb.Sheets("XXXXX") 
Set objRE1 = New RegExp 
    With objRE1 
     .Pattern = "Invalid Response received from system" 
     .IgnoreCase = True 
     .Global  = False 
    End With 

    Set objRE2 = New RegExp 

    With objRE2 
     .Pattern = "Enterprise Data mapping cannot be found" 
     .IgnoreCase = True 
     .Global  = False 
    End With 

    Set objRE3 = New RegExp 

    With objRE3 
     .Pattern = "Caught exception and rethrowingError detected" 
     .IgnoreCase = True 
     .Global  = False 
    End With 

    xf = 0 
    re = 0 
    gg = 0 
    rst = 0 

    For Each cell In ws.UsedRange.Columns(11).Cells 
     str = cell.Value 
     If objRE1.Test(str) Then 
       xf = xf + 1 
     Elseif objRE2.Test(str) Then 
       re = re + 1 
     Elseif objRE3.Test(str) Then 
       gg = gg + 1 
     Else 
       rst = rst + 1 
     End If  
    Next 

    Set objWorksheet = xl.ActiveWorkbook.Worksheets(2) 
    objWorksheet.Cells(5,5).Value = "Invalid Response received from system " 
    objWorksheet.Cells(6,5).Value = "Enterprise Data mapping cannot be found " 
    objWorksheet.Cells(7,5).Value = "Caught exception and rethrowingError detected " 
    objWorksheet.Cells(8,5).Value = "Errors With new String patterns found " 

    'WScript.Echo xf 
    objWorksheet.Cells(5,6).Value = xf 
    objWorksheet.Cells(6,6).Value = re 
    objWorksheet.Cells(7,6).Value = gg 
    objWorksheet.Cells(8,6).Value = rst 

    wb.Saved = True 
    wb.Close 

Set objRE1 = Nothing 
Set objRE2 = Nothing 
xl.Quit 

在第二片的值是沒有得到書面或保存。

另一點 - 我看到文件以某種方式被保存在「我的文檔」下。也許這也是有人可以指出的。

回答

1
wb.Save 
wb.Close true, "C:\XXXSample_Data.xlsx" 

設置wb.Saved = True將工作簿標記爲保存而不保存。

Close的參數是:改變(true)和路徑保存到其中的變化將被保存

文件