ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Highlight Selected Excel file in Explorer (https://www.excelbanter.com/excel-programming/408619-highlight-selected-excel-file-explorer.html)

moonhk[_2_]

Highlight Selected Excel file in Explorer
 
Hi Reader

Do you know how to higlight selected Excel file in Explorer ?


Sub APOpen_FileLocation()
Dim objFSO, objShell, strDir, strName
strDir = ActiveWorkbook.Path
strName = ActiveWorkbook.FullName
On Error Resume Next
'MsgBox strDir
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDir = objFSO.getFolder(strDir)
If Err.Number = vbEmpty Then
Set objShell = CreateObject("WScript.shell")
objShell.Run ("Explorer" & " " & strDir)
'~~ Highlight Selected Excel file in explorer
End If
Set objFSO = Nothing
Set objShell = Nothing
Set strDir = Nothing
End Sub

Ivyleaf

Highlight Selected Excel file in Explorer
 
Hi Moonhk,

You were very close.

Sub APOpen_FileLocation()
Dim objShell As Object, strName As String
strName = ActiveWorkbook.FullName
On Error Resume Next
If Err.Number = vbEmpty Then
Set objShell = CreateObject("WScript.shell")
objShell.Run ("Explorer /select," & strName)
End If
Set objShell = Nothing
Set strDir = Nothing
End Sub

Cheers,
Ivan.

On Apr 1, 6:33*pm, moonhk wrote:
Hi Reader

Do you know how to higlight selected Excel file in Explorer ?

Sub APOpen_FileLocation()
Dim objFSO, objShell, strDir, strName
* *strDir = ActiveWorkbook.Path
* *strName = ActiveWorkbook.FullName
* *On Error Resume Next
* *'MsgBox strDir
* * Set objFSO = CreateObject("Scripting.FileSystemObject")
* * strDir = objFSO.getFolder(strDir)
* * If Err.Number = vbEmpty Then
* * * * Set objShell = CreateObject("WScript.shell")
* * * * objShell.Run ("Explorer" & " " & strDir)
* * * * '~~ Highlight Selected Excel file in explorer
* * End If
* * Set objFSO = Nothing
* * Set objShell = Nothing
* * Set strDir = Nothing
End Sub




All times are GMT +1. The time now is 06:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com