Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    GetFileOpen (Excel XP)

    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: GetFileOpen (Excel XP)

    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

  3. #3
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: GetFileOpen (Excel XP)

    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.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: GetFileOpen (Excel XP)

    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?

  5. #5
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: GetFileOpen (Excel XP)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •