excelvba呼叫windowsAPI快速查詢所選擇的檔案
excel選中檔名清單、自動從“a1"資料夾中查詢相應的檔案。
ShellExecuteA,DataObject,Clipboard,find,SendKeys
PrivateDeclareFunctionShellExecuteLib"shell32.dll"Alias_
"ShellExecuteA"(ByValhwndAsLong,ByVallpszOpAs_
String,ByVallpszFileAsString,ByVallpszParamsAsString,_
ByVallpszDirAsString,ByValFsShowCmdAsLong)AsLong
ConstSW_SHOW=5
Subtest()
Selection.Copy
DimMyDataAsDataObject
DimsTempAsString,sAsString
SetMyData=NewDataObject
MyData.GetFromClipboard
sTemp=MyData.GetText
s=Replace(sTemp,vbCrLf,";")
s=Replace(s,vbTab,";")
MyData.SetText(s)
MyData.PutInClipboard
ShellExecute0&,"find",Range("a1"),_
vbNullString,vbNullString,SW_SHOW
Application.Wait(Now+TimeValue("0:00:02"))
SendKeyss&"{ENTER}"
EndSub
excelvba呼叫windowsAPI快速查詢所選擇的檔案
excel選中檔名清單、自動從“a1"資料夾中查詢相應的檔案。
ShellExecuteA,DataObject,Clipboard,find,SendKeys
PrivateDeclareFunctionShellExecuteLib"shell32.dll"Alias_
"ShellExecuteA"(ByValhwndAsLong,ByVallpszOpAs_
String,ByVallpszFileAsString,ByVallpszParamsAsString,_
ByVallpszDirAsString,ByValFsShowCmdAsLong)AsLong
ConstSW_SHOW=5
Subtest()
Selection.Copy
DimMyDataAsDataObject
DimsTempAsString,sAsString
SetMyData=NewDataObject
MyData.GetFromClipboard
sTemp=MyData.GetText
s=Replace(sTemp,vbCrLf,";")
s=Replace(s,vbTab,";")
MyData.SetText(s)
MyData.PutInClipboard
ShellExecute0&,"find",Range("a1"),_
vbNullString,vbNullString,SW_SHOW
Application.Wait(Now+TimeValue("0:00:02"))
SendKeyss&"{ENTER}"
EndSub