Announcement

Collapse
No announcement yet.

VBA: Opening file error "False.xls could not be found..."

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBA: Opening file error "False.xls could not be found..."



    I am trying to open a file using this code:

    Workbooks.Open Filename:=Application.GetOpenFilename("PRODDATA file,*.xls")

    When the Open File dialog window opens and I click on "Cancel", I get a Runtime error "1004" False.xls could not be found..."


    How can I avoid this error?


    Thanks,
    Rich D

  • #2
    Try
    Dim fn
    fn = Application.GetOpenFilename("PRODDATA file,*.xls")
    If fn = False Then Exit Sub
    Workbooks.Open FileName:=fn
    Please do not U2U (private message) me directly for questions that should be posted to the forum; any such U2Us will be ignored.

    Comment


    • #3
      Hi Rich,

      Get the filename variable first, then test it, then open the workbook. Like this:
      Code:
      Sub test()
          Dim varName As Variant
          
          varName = Application.GetOpenFilename(Title:="Hello!")
          If varName = False Then Exit Sub
          Workbooks.Open FileName:=varName
      
      End Sub
      HTH

      EDIT : Hello Derk - on the ball I see!
      Cross-poster? Read this: Cross-posters
      Struggling to use tags (including Code tags)? : Forum tags

      Comment


      • #4


        Thank you, gentlemen all!

        Rich D

        Comment

        Working...
        X