vbs脚本:ExplorerSel

本文介绍了一段VBA代码,用于在Windows资源管理器中打开特定路径的文件或文件夹,并将其选中。该代码适用于需要自动化文件管理任务的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Rem :  ===========  打开浏览器,选中指定文件或文件夹
Rem :  ===========  文件或文件夹必须存在
Sub ExplorerSel(path)
	Dim f
	f = Trim( path )
	If Right(f,1) = "/" Then f = Left(f,Len(f) -1 )
	If fso.fileexists(f) = False And fso.folderexists(f) = False Then Err.Raise vbObjectError+128, "ExplorerSel", f & " does not exists"

    
	Dim errMsg
	On Error Resume Next
	Rem  ======  code begin
	shell.Run "explorer.exe /select," & Chr(34) & f & Chr(34),1,TRUE
	Rem  ======  code end
	If Err.Number <> 0 Then
		errMsg = Err.Description
		On Error Goto 0
		Err.Raise vbObjectError+128, "ExplorerSel", errMsg & vbNewLine & _
								"                path:" & vbTab & path
		Exit Sub
	End If

End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值