Option Explicit Private Sub Command1_Click()
Dim sourceFile As String
Dim destinationFile As String
sourceFile = "C:\档案统计表.xls"
destinationFile = Replace(sourceFile, ".xls", "1.xls")
If Dir(destinationFile) <> "" Then
Kill destinationFile
End If
FileCopy sourceFile, destinationFile
findKey destinationFile, "销售"
End Sub Sub findKey(ByVal filepath As String, ByVal key As String)
Dim excelObj As Excel.Application
Dim bookObj As Excel.Workbook
Dim sheetObj As Excel.Worksheet
Set excelObj = CreateObject("Excel.Application")
Set bookObj = excelObj.Workbooks.Open(filepath)
excelObj.Visible = False
Set sheetObj = bookObj.Worksheets(1)
sheetObj.Activate
Dim findObj
Set findObj = excelObj.Cells.Find(What:=key, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=False, SearchFormat:=False)'此句出错
If Not findObj Is Nothing Then
Dim firstAddress
firstAddress = findObj.Address
Do
findObj.Activate
With excelObj.Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
' excelObj.Selection.Font.Bold = True
Set findObj = excelObj.Cells.FindNext(findObj)
Loop While Not findObj Is Nothing And findObj.Address <> firstAddress
End If
Set findObj = Nothing bookObj.Save
bookObj.Close
Set bookObj = Nothing
Set sheetObj = Nothing
excelObj.Quit
Set excelObj = Nothing
End Sub
上面的代码执行第一次没有问题,再执行第二次就报错,我看了进程里面第一次执行完,EXCEL.EXE没有关掉,可是我已经Set excelObj = Nothing,为什么还有EXCEL.EXE存在呢? 不好意思,就剩8分了,希望大家不要嫌少!
http://topic.csdn.net/u/20081021/14/9708f453-2494-4b00-826d-839db827d15b.html?seed=328649239
上面的100分,是同一个问题,我在vba版提了,没人顶,发这来试试!
Dim sourceFile As String
Dim destinationFile As String
sourceFile = "C:\档案统计表.xls"
destinationFile = Replace(sourceFile, ".xls", "1.xls")
If Dir(destinationFile) <> "" Then
Kill destinationFile
End If
FileCopy sourceFile, destinationFile
findKey destinationFile, "销售"
End Sub Sub findKey(ByVal filepath As String, ByVal key As String)
Dim excelObj As Excel.Application
Dim bookObj As Excel.Workbook
Dim sheetObj As Excel.Worksheet
Set excelObj = CreateObject("Excel.Application")
Set bookObj = excelObj.Workbooks.Open(filepath)
excelObj.Visible = False
Set sheetObj = bookObj.Worksheets(1)
sheetObj.Activate
Dim findObj
Set findObj = excelObj.Cells.Find(What:=key, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, MatchByte:=False, SearchFormat:=False)'此句出错
If Not findObj Is Nothing Then
Dim firstAddress
firstAddress = findObj.Address
Do
findObj.Activate
With excelObj.Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
' excelObj.Selection.Font.Bold = True
Set findObj = excelObj.Cells.FindNext(findObj)
Loop While Not findObj Is Nothing And findObj.Address <> firstAddress
End If
Set findObj = Nothing bookObj.Save
bookObj.Close
Set bookObj = Nothing
Set sheetObj = Nothing
excelObj.Quit
Set excelObj = Nothing
End Sub
上面的代码执行第一次没有问题,再执行第二次就报错,我看了进程里面第一次执行完,EXCEL.EXE没有关掉,可是我已经Set excelObj = Nothing,为什么还有EXCEL.EXE存在呢? 不好意思,就剩8分了,希望大家不要嫌少!
http://topic.csdn.net/u/20081021/14/9708f453-2494-4b00-826d-839db827d15b.html?seed=328649239
上面的100分,是同一个问题,我在vba版提了,没人顶,发这来试试!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货