• GetFileOpen (Excel XP)

    Author
    Topic
    #405226

    I have this code…

    Sub cmdCSVfile_Click()
    Dim fileToopen As Variant

    fileToopen = Application _
    .GetOpenFilename(“CSV Files (*.csv), *.csv”)

    If fileToopen “” Then
    Sheets(“Input”).Select
    Range(“B4”).Value = fileToopen
    End If

    End Sub

    That is on the click event of a cmd button i have on an excel worksheet i have. It opens the folder and i navigate to the proper file. Then i doubleclick on the file and get an error. I was trying to get the file name to go in the B4 cell on my input sheet. Can someone help me with what i am doing wrong. Thank you.

    Viewing 1 reply thread
    Author
    Replies
    • #830367

      Range(“B4”) refers to the sheet containing the command button. Replace

      Sheets(“Input”).Select
      Range(“B4”).Value = fileToopen

      by

      Sheets(“Input”).Range(“B4”).Value = fileToopen

      • #830369

        I tried that and i get “Code execution has been interrupted”

        The code resumes execution if i press F8 in the IDE but i think the problem has to do when i have the view of the folder contents, i choose a file and double-click on it and then i get the error.

        It has something to do with double-clicking on the file. I don’t know how else to “choose” it. thank u for the help.

        • #830373

          Are your worksheets protected perhaps? The code works OK for me. By the way, you can also select a file by single-clicking it, and then clicking the “Open” button in the dialog.

          I have attached my test workbook. Does that work for you?

          • #830381

            i changed it to activesheet.range(“B4”) and that works. the cmd button is on the same sheet as where i want the filename B4 to be places.

            It works now. Thank you so much for the help.

          • #830382

            i changed it to activesheet.range(“B4”) and that works. the cmd button is on the same sheet as where i want the filename B4 to be places.

            It works now. Thank you so much for the help.

        • #830374

          Are your worksheets protected perhaps? The code works OK for me. By the way, you can also select a file by single-clicking it, and then clicking the “Open” button in the dialog.

          I have attached my test workbook. Does that work for you?

      • #830370

        I tried that and i get “Code execution has been interrupted”

        The code resumes execution if i press F8 in the IDE but i think the problem has to do when i have the view of the folder contents, i choose a file and double-click on it and then i get the error.

        It has something to do with double-clicking on the file. I don’t know how else to “choose” it. thank u for the help.

    • #830368

      Range(“B4”) refers to the sheet containing the command button. Replace

      Sheets(“Input”).Select
      Range(“B4”).Value = fileToopen

      by

      Sheets(“Input”).Range(“B4”).Value = fileToopen

    Viewing 1 reply thread
    Reply To: GetFileOpen (Excel XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: