I am using the below code to open any local file or hyperlink found on my Selection.
The code itself run as expected, But If applied an autoFilter on the sheet and I select manually non continuous cells on the same column,
I found out that my selection contains also the hidden cells in-betweens and subsequently unwanted links are opened.
My question, Is How to modify the below code to run on (includes) the apparent selection only?
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As LongPtr, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
Sub OpenDocument2() 'ShellExecute
Dim cel As Range, El, arrCel
For Each cel In Selection.Cells
If cel.Hyperlinks.Count > 0 Then
ShellExecute 0, "open", (cel.Hyperlinks(1).Address), "", "", 1
Else
arrCel = Split(cel.value, vbLf)
For Each El In arrCel
ShellExecute 0, "open", (El), "", "", 1
Next El
End If
Next cel
End Sub
>Solution :
You can use
For Each cel In Selection.SpecialCells(xlCellTypeVisible)
which only returns visible, i.e. filtered cells