您好AHKer我是新手,我用这个来从Excel中的剪贴板中查找文本,如果在Column.B中找到关键字,复制特定的单元格,然后循环直到找不到,但是不起作用......根本不可能有人帮我一个忙吗?如何使它工作?谢谢!
#SingleInstance force Ignore off
SetDefaultMouseSpeed, 0
IfWinExist, ahk_class Progman
WinActivate
Sleep 100
PostMessage, 0x50, 0x0804,0,, A
clipboard =
Sleep 300
IfWinExist, huasheng
WinActivate
Sleep 500
KeyWait, LButton, D
Sleep 1000
Click 3
Send, ^c
ClipWait
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
var := clipboard
var := SubStr(var, InStr(var, "%A_Space%") + 1, InStr(var, "(") - InStr(var, "):") - 3)
Clipboard := var
Xl := ComObjCreate("Excel.Application")
Xl.Visible := True
Xl := ComObjActive("Excel.Application")
wbk := Xl.Workbooks.Open("C:\Users\iViLL\Google Drive\Doc\ExportOrderList201606161859.Xlsx")
t := %Clipboard%, found := false
x := Xl.Range("B:B").Find(t).row
for Sheet, in wbk.Sheets
{
if (!c := x)
continue
if (!found)
found := true
first := c.Value
Loop
{
Xl.Range("A" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
MyVar1 :=Clipboard
Xl.Range("B" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
MyVar2 :=Clipboard
Xl.Range("J" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
MyVar3 :=Clipboard
Xl.Range("K" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
StringReplace, clipboard, clipboard, %A_Space%,, all
MyVar4 :=Clipboard
Xl.Range("H" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
MyVar5 :=Clipboard
Xl.Range("M" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
MyVar6 :=Clipboard
Xl.Range("N" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
MyVar9 :=Clipboard
Xl.Range("U" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
StringReplace, clipboard, clipboard, %A_Space%,, all
MyVar7 :=Clipboard
Xl.Range("AA" x).Copy
StringReplace, clipboard, clipboard, `n,, all
StringReplace, clipboard, clipboard, `r,, all
StringReplace, clipboard, clipboard, %A_Space%,, all
MyVar8 :=Clipboard
IfWinExist Untitled - Notepad
{
WinActivate
WinWaitActive Untitled - Notepad
}
else
IfWinNotExist Untitled - Notepad
{
run, C:\WINDOWS\system32\notepad.exe
WinWaitActive Untitled - Notepad
}
Sleep 1000
SendRaw ID:%MyVar2%`nNum:%MyVar1%`nStatus:%MyVar5%`nAddress:%MyVar3%,%MyVar6%,%MyVar9%,%MyVar4%
If (MyVar8)
{
IfInString, MyVar7, New Address
{
SendRaw `n%MyVar7%
}
else
IfNotInString, MyVar7, New Address
{
SendRaw `nNew Address:%MyVar3%,%MyVar6%,%MyVar9%,%MyVar8%
}
}
else
{
Sleep 100
}
Sleep 500
Send, ^a
Sleep 100
Send, ^c
Sleep 100
Send, {Delete}
Sleep 300
Winclose, Untitled - Notepad
IfWinExist, huasheng
WinActivate
WinWaitActive huasheng
Send, ^v
c := Sheet.Range("B:B").FindNext(c)
} Until (c.Value = first)
}
if (!found)
msgbox not found!
Return
答案 0 :(得分:0)
您可以使用excel自己的“匹配”功能来完成任务。我之前做过这种事情,这里的例子是循环'删除包含特定文本或值的行
xl := ComObjGet(newestFile)
zeros := xl.Application.WorksheetFunction.CountIf(xl.Sheets("Detail").Range("x:x"), "0")
Loop, %zeros%{
zeros := xl.Application.WorksheetFunction.MATCH("0", xl.Sheets("Detail").Range("x:x"), 0)
xl.Sheets("Detail").Range(xl.Sheets("Detail").Cells(zeros,4).address,xl.Sheets("Detail").Cells(zeros,6).address).EntireRow.Delete
}