I have used this code hundreds of times -- for some reason when I browse no files appear for selection. I verified that the folder contains spreadsheets and other files. Any ideas?
Thanks.
Public Function BrowseForFile() Dim fDialog As Office.FileDialog Dim varFile As Variant Dim strLinkToFile As String strLinkToFile = "" Set fDialog = Application.FileDialog(msoFileDialogFilePicker) With fDialog .AllowMultiSelect = False .Title = "Browse for Spreadsheet" .Filters.Clear .Filters.Add "Spreadsheets", "*.xls" .Filters.Add "All Files", "*.*" If .Show = True Then For Each varFile In .SelectedItems strLinkToFile = varFile LinkExcelSpreadsheet (strLinkToFile) Next Else Exit Function End If End WithEnd Function
try doing a compact and repair
from VBA window do a DEBUG > Compile
correct any errors raised
your code looks ok
0
Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.
I'll agree with @mbizup.
How and why you are getting TEMP in the filename box is what's queering it up.
Manually clear that, and move up a level / down a level and you should be good.
But now, where is TEMP coming from?
It's not from the code
Explaining my comment at http:#a36503972... according to the picture you posted, it is looking for Temp.xls, and from the lower image it is not there.
If you remove the 'Temp' from the filename box, it should show all .xls files.
If you manually remove 'Temp' from the filename box, you'll have to click outside of the filename box for that change to be reflected in the filtered files.
As a stopgap --since we don't know where TEMP is coming from -- you could force it to not have an initial value
Public Function BrowseForFile()
Dim fDialog As Office.FileDialog
Dim varFile As Variant
Dim strLinkToFile As String
strLinkToFile = ""
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
.AllowMultiSelect = False
.Title = "Browse for Spreadsheet" .InitialFileName =""
.Filters.Clear
.Filters.Add "Spreadsheets", "*.xls"
.Filters.Add "All Files", "*.*"
If .Show = True Then
For Each varFile In .SelectedItems
strLinkToFile = varFile
LinkExcelSpreadsheet (strLinkToFile)
Next
Else
Exit Function
End If
End With