在excel vba中如何调用api函数实现快速查找文件名

在excel vba中如何调用api函数实现快速查找文件名,第1张

excel vba调用windows API 快速查找所选择的文件

excel选中悉氏文件名清单、自动从“a1"文件夹中查找相应的文件。

ShellExecuteA,DataObject,Clipboard,find,SendKeys

Private Declare Function ShellExecute Lib "shell32.dll" Alias _

"ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _

String, ByVal lpszFile As String, ByVal lpszParams As String, _

ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long

Const SW_SHOW = 5

Sub test()

Selection.Copy

Dim MyData As DataObject

Dim sTemp As String, s As String

Set MyData = New DataObject

MyData.GetFromClipboard

sTemp = MyData.GetText

s = Replace(sTemp, vbCrLf, "")

s = Replace(s, vbTab, "")

MyData.SetText (s)

MyData.PutInClipboard

ShellExecute 0&, "find", Range("a1"笑型), _

vbNullString, vbNullString, SW_SHOW

Application.Wait (Now + TimeValue("0:00:02"睁升散))

SendKeys s &"{ENTER}"

End Sub

多看看MSDN,自己就可以摸索出来。 if (GetOpenFileName(&ofn)==TRUE) { TCHAR *pfileTCHAR szFileNames[MAX_PATH*10]TCHAR path[MAX_PATH],szFileName[MAX_PATH]szFileNames[0]=TEXT('\0'肆局悄)lstrcpyn(path, ofn.lpstrFile, ofn.nFileOffset ) path[ ofn.nFileOffset ] = TEXT('\0') if( path[lstrlen(path)-1] != TEXT('\\') ) lstrcat(path, TEXT("\\腊森")) for(pfile=ofn.lpstrFile+ofn.nFileOffset*pfile!=TEXT('\0')pfile+=lstrlen(pfile)+1) { szFileName[0]=TEXT('\0')lstrcat(szFileName, path)lstrcat(szFileName, pfile)//szFileName就是每一个带路径的文件名。 lstrcat(szFileNames, szFileName)lstrcat(szFileNames, TEXT("裂渣\n"))} MessageBox(NULL, szFileNames, TEXT("MultiSelect"), MB_OK) }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12212298.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存