MDC Controls
New Member
- Joined
- Jun 7, 2013
- Messages
- 1
Many thanks to all at Mr. Excel for all the help I have already received searching for tips and tricks. I am a new registered user and this is my first post. I could not figure this one out.
I have a spreadsheet with a list of Event Documents and their file paths. I have some code that lists the documents in a form Listbox. When a listbox item is selected, I have other code that identifies the row number in the spreadsheet corresponding to the Listbox ListIndex, counts the appropriate number of rows down the spreadsheet to identify the file path in the adjacent column to display the contents in an adjacent Textbox.
This works great until I filter the spreadsheet. I am successful at listing the filtered cells into the Listbox, but when I select a document on the form’s Listbox, it counts down the invisible cells as well as the visible cells, but I only want it to count the visible cells.
Below is the code:
I have a spreadsheet with a list of Event Documents and their file paths. I have some code that lists the documents in a form Listbox. When a listbox item is selected, I have other code that identifies the row number in the spreadsheet corresponding to the Listbox ListIndex, counts the appropriate number of rows down the spreadsheet to identify the file path in the adjacent column to display the contents in an adjacent Textbox.
This works great until I filter the spreadsheet. I am successful at listing the filtered cells into the Listbox, but when I select a document on the form’s Listbox, it counts down the invisible cells as well as the visible cells, but I only want it to count the visible cells.
Below is the code:
Code:
Private Sub ListBox_ER_List_Click()
Dim sTxt$, sText$, sPath$, sLIV$
' This identifies the row number in the spreadsheet, _
corresponding to the Listbox slection:
sLIV = ListBox_ER_List.ListIndex + 2
' This identifies the path. listed in the F column of the spreadsheet _
it works great if the spreasheet is not filtered
sPath = Worksheets("Event_Directory").Range("f" & sLIV).Value
' This is an example of various attempts to do the same as the above, _
but with the visible cells only:
sPath = Worksheets("Event_Directory").SpecialCells(xlCellTypeVisible).Range("f" & sLIV).Value
'the above creates RunTime Error 438 - Object doesn't support this property or method
'This is the rest of the code that follows the path (sPath) and then displays _
the contents of the document in an adjacent Textbox whitout problems
If Dir(sPath) = "" Then
MsgBox "File was not found."
Exit Sub
End If
Close
Open sPath For Input As #1
Do Until EOF(1)
Line Input #1, sTxt
sText = sText & sTxt & vbLf
Loop
Close
sText = Left(sText, Len(sText) - 1)
Me.TextBox_Txt.Text = sText
End Sub