只是为了更新,这是工作代码
- '
- ' work done in excel
- '
- Sub excelwork()
- Dim i As Integer, n As Long, c As Long
- c = 8
- Dim CurrentItem As String
- Dim pause As Boolean
- Dim match As Variant
- Dim NewSheetName As String
- NewSheetName = Dwg_Name & "assets"
-
- 'set a count for items in collection
- For i = 1 To EOC
- Cur_TxtSTR = text_coll(i)
- MasWorksheet.Activate
- MasWorksheet.cells(1, 3).Activate
-
- 'set a count for items in excel spreadsheet
- For n = 1 To 876
- CurrentItem = MasWorksheet.cells(n, 3).Value
-
- 'compare collection item to each excel item, until we find our match
- If Cur_TxtSTR = CurrentItem Then
- MasWorksheet.Rows(n).Select ' select the row
- MasWorksheet.Rows(n).Copy ' copy the row
- secWorksheet.Activate
- secWorksheet.cells(c, 1).Activate
- secWorksheet.paste ' paste the row in the new sheet
- secWorksheet.cells(c, 10).Value = Dwg_Name ' insert the drawing name in new sheet
- c = c + 1
- End If
-
- Next n
-
- Next i
-
- secWorksheet.Copy ' copy the new sheet
- ExcelServer.activeworkbook.sheets("template").Name = NewSheetName ' set the new sheet name
- FileSaveName = ExcelServer.Application.GetSaveAsFilename _
- (InitialFileName:=Dwg_Name & ".xls", Title:="Save As") ' choose where we're going to save it
-
- If FileSaveName = "False" Then ' error handleing
- MsgBox "File not Saved, Actions Cancelled."
- Exit Sub
- Else
- ExcelServer.activeworkbook.SaveAs FileSaveName ' save it
- ExcelServer.activeworkbook.Close ' close it
- End If
-
- ExcelServer.Application.DisplayAlerts = False ' hide unwanted alerts
- ExcelServer.workbooks("bptags.xls").Close ' close the work book
- ExcelServer.Quit ' quit excel
- set_to_nil ' function to reset object variables to nothing
-
- End Sub
这是我的博客,可以随意访问并查看或更正
http://showyourcode.blogspot.com/ |