none
How I get filepath by select file in webbrowser control? RRS feed

  • Question

  • Hi @ all

    I have placed a webbrowser control in a userform. I would like  use the webbrowser control to select file and get file path to import in excel. The browse function work fine but I don't get the path by click on file symbol. I have no click event. Has someone a solution for me? I would like have the path of selected excel file (mytest.xlsx).

    Thanks

    Monday, October 6, 2014 6:10 PM

Answers

  • Hi Boy88,

    As far as I know, the WebBrowser control doesn’t export the API to get the information of the selected file.

    So I suggest that you could use FileDialog to select the file.

    For example:

    Sub  SelectFile()
    Dim  intChoice As  Integer 
    Dim  strPath As  String 
    Dim  i As  Integer 
    
    'allow the user to select multiple files 
    Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = True
    'make the file dialog visible to the user 
    intChoice = Application.FileDialog(msoFileDialogOpen).Show
    'determine what choice the user made 
    If  intChoice <> 0 Then 
        'get the file path selected by the user 
        For  i = 1 To  Application.FileDialog(msoFileDialogOpen _ 
            ).SelectedItems.Count 
            strPath = Application.FileDialog(msoFileDialogOpen _ 
            ).SelectedItems(i) 
            'print the file path to sheet 1 
            Cells(i + 1, 1) = strPath 
        Next  i 
    End If

    Best Regards

    Starain Chen


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 8, 2014 1:45 AM
    Moderator

All replies

  • Can you not retrieve it by the LocationName or LocationURL property of the resource?

    See also: WebBrowser Object

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

    Monday, October 6, 2014 10:42 PM
  • Hi

    thanks for answering but I try to find the right event to use your proposed command. It is no click event available. How can I create me own click event for this control?

    any Idea?

    Tuesday, October 7, 2014 8:55 AM
  • Hi Boy88,

    As far as I know, the WebBrowser control doesn’t export the API to get the information of the selected file.

    So I suggest that you could use FileDialog to select the file.

    For example:

    Sub  SelectFile()
    Dim  intChoice As  Integer 
    Dim  strPath As  String 
    Dim  i As  Integer 
    
    'allow the user to select multiple files 
    Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = True
    'make the file dialog visible to the user 
    intChoice = Application.FileDialog(msoFileDialogOpen).Show
    'determine what choice the user made 
    If  intChoice <> 0 Then 
        'get the file path selected by the user 
        For  i = 1 To  Application.FileDialog(msoFileDialogOpen _ 
            ).SelectedItems.Count 
            strPath = Application.FileDialog(msoFileDialogOpen _ 
            ).SelectedItems(i) 
            'print the file path to sheet 1 
            Cells(i + 1, 1) = strPath 
        Next  i 
    End If

    Best Regards

    Starain Chen


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 8, 2014 1:45 AM
    Moderator