使用宏搜索时,我无法搜索excel表中我知道的单词。我检查了所有选项,但无法找到为什么会发生这种情况。 var2是1082591.html和1082592.html等等。当我在excel中找到Total时,它找不到它。感谢
Sub DataPull()
Dim Website
Application.DisplayAlerts = False
var1 = 2
Do Until Range("A" & var1) = ""
var2 = Range("A" & var1).Value
Hostteam = Range("C" & var1).Value
Hosts = Hostteam & " innings"
Visitorteam = Range("D" & var1).Value
Visitors = Visitorteam & " innings"
Website = "http://www.espncricinfo.com/indian-premier-league-2017/engine/match/" & var2
Set myIE = CreateObject("InternetExplorer.Application")
myIE.Navigate Website
myIE.Visible = True
Application.Wait Now + TimeSerial(0, 0, 5)
SendKeys "^a"
Application.Wait Now + TimeSerial(0, 0, 1)
SendKeys "^c"
Application.Wait Now + TimeSerial(0, 0, 1)
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=var2
ActiveSheet.Paste
Application.Wait Now + TimeSerial(0, 0, 10)
Cells.Find(What:=Hosts, After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Cells.Find(What:="Total", After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 2).Copy
ThisWorkbook.Activate
Range("J" & var1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Workbooks(var2).Activate
Cells.Find(What:=Visitors, After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Cells.Find(What:="Total", After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 2).Copy
ThisWorkbook.Activate
Range("L" & var1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
myIE.Quit
Set myIE = Nothing
Err.Clear
Workbooks(var2).Activate
ActiveWorkbook.Close
ThisWorkbook.Activate
Range("O" & var1).Value = "Done"
var1 = var1 + 1
Loop
End Sub
答案 0 :(得分:0)
在搜索“Totals”之前写下这两行,看看你的活动单元格是什么,以及在哪张表中:
debug.print activecell.address
debug.print activecell.parent.name
Cells.Find(What:="Total", After:=ActiveCell, LookIn:= _
xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 2).Copy
这可能是找不到它的原因。如果是这种情况,请考虑不要搜索After:ActiveCell
,而是使用变量进行设置。