Q友MicrosoftCTO向我提出这个问题,他很郁闷的说他搞了一个星期
其实很简单,我把它写成了通用的函数了,大家要用的话直接 Ctrl+C
'程序设计:唐细刚 2006 2006-4-19 At shenzhen
'函数:OpenFolderAndSelectSpecialFile
'用途:打开指定的文件夹并且选中指定的文件
'参数:szSpecialFileForSelect 想要选中的文件全路径
'返回:True:选中文件成功 False: 选中文件失败或者指定文件不存在
Public Function OpenFolderAndSelectSpecialFile(ByVal szSpecialFileForSelect As String) As Boolean
On Error GoTo hErr
If Dir(szSpecialFileForSelect) <> "" Then
Dim szShellSelect As String
szShellSelect = "Explorer /select, "
szShellSelect = szShellSelect & szSpecialFileForSelect
Shell szShellSelect, vbNormalFocus
OpenFolderAndSelectSpecialFile = True
End If
Exit Function
hErr:
End Function
'调用举例:
Private Sub Command1_Click()
Call OpenFolderAndSelectSpecialFile("C:\Program Files\Internet Explorer\IEXPLORE.EXE")
End Sub