doctortt
05-06-2011, 07:44 PM
I have a button that will launch the open file prompt, but if i click cancel, it will popout an error message.  How do you handle this? I don't want to use  "On Error GoTo BlahBlah"
Kenneth Hobs
05-06-2011, 09:41 PM
Without seeing code, it is hard to give advice.  I would do it like this:
Sub Test()
  MsgBox FileOpen("x:\", "Excel Files", "*.xls,*.xlsm,*.xlsx")
End Sub
Function FileOpen(initialFilename As String, _
  Optional sDesc As String = "Excel (*.xls)", _
  Optional sFilter As String = "*.xls") As String
  With Application.FileDialog(msoFileDialogOpen)
    .ButtonName = "Open"
    .initialFilename = initialFilename
    .Filters.Clear
    .Filters.Add sDesc, sFilter
    .Title = "File Open"
    .AllowMultiSelect = False
    .InitialView = msoFileDialogViewDetails
    If .Show = -1 Then FileOpen = .SelectedItems(1)
  End With
End Function
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.