使用vbscript编辑excel文件但编辑过程需要很长时间才能完成

时间:2017-07-06 05:13:59

标签: excel vba excel-vba vbscript

/ *我使用vb scrips编辑excel文件的原因是:excel文件将始终不同,但格式相同,用户不希望在工作簿上保存VBA宏。

我从第3列获取值,并在结尾处将这些值添加到第9列。

* /

Set xlApp=CreateObject("Excel.Application")
Set xlBook=xlApp.Workbooks.Open("filepath", 0, true)
xlApp.visible=true


Set xlSheet=xlBook.Worksheets("Proposal Spreadsheet")
row=xlSheet.UsedRange.Rows.Count
col=xlSheet.UsedRange.Columns.Count

dim i 

For i=15 to xlSheet.UsedRange.Rows.Count 
cell=xlSheet.Cells(i,3).Value
celli=xlSheet.Cells(i,9).Value+"("+cell+")" //I am combining column 3 with column 9

xlSheet.Cells(i,9).Value=celli


Next

xlBook.Save
xlApp.Run "Submit_To_iDesk"
xlBook.Close

xlApp.Quit
Set xlApp=Nothing 
Set xlBook=Nothing 
WScript.Quit

2 个答案:

答案 0 :(得分:1)

如果NSDictionary *oldDict = (NSDictionary *)[dataArray objectAtIndex:0]; NSMutableDictionary *newDict = [NSMutableDictionary dictionaryWithDictionary:oldDict]; [newDict setObject:@"Don" forKey:@"Name"]; [dataArray replaceObjectAtIndex:0 withObject:newDict]; 没有返回有用的数字,请使用一种更可靠的方法来查找列中最后使用过的单元格:

UsedRange

答案 1 :(得分:1)

加快程序的关键是减少写入操作的次数 我就是这样做的

  • 将范围变量(目标)设置为第9列中的目标单元格
  • 从目标范围
  • 创建数组
  • 编辑values数组的元素将values数组写回原始
  • 1次操作中的目标范围
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Users\best buy\Desktop\Book1.xlsx", 0, True)

xlApp.Visible = True
xlApp.ScreenUpdating = False
Set xlSheet = xlBook.Worksheets("Proposal Spreadsheet")

Dim i, values, LastRow, target

With xlSheet
    LastRow = xlSheet.UsedRange.Rows.Count
    Set target = .Range(.Cells(15, 9), .Cells(LastRow, 9))
    values = target.Value

    For i = LBound(values, 1) To UBound(values, 1)
        values(i, 1) = values(i, 1) & "(" & .Cells(i + 15 - LBound(values, 1), 3) & ")"
    Next
    target.Value = values
End With

xlBook.Save
'xlApp.Run "Submit_To_iDesk"
xlBook.Close
xlApp.ScreenUpdating = True
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
WScript.Quit