Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2004
    Location
    San Antonio, TX
    Posts
    2

    Unanswered: Using VBA to Create Input Box with Browse Button

    I am using VBA to input data from csv datafiles. Currently, I have to use the InputBox function and type in the name of the file I want to use. Because typos are abundant (at least with me), I would like to use a box that allows me to browse the files on my hard drive. I see the box when I select "Start" and "Run" in windows, so I know it can be done, but I can't find it in VBA help. Anybody have any ideas?

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067

    Open File Dialog

    The line of Code you are after to get the openfiledialog box is

    Application.GetOpenFilename

    this will produce the dialog box and then pass a string variable of the path to a variable.

    Ive produced a quick example that will put the path name you select into a text box then when you press ok it will open the workbook

    if it hasnt appeared i will e-mail it to you if you would like it.

    David

  3. #3
    Join Date
    Dec 2003
    Location
    Östersund Sweden
    Posts
    60
    Hi,

    In addition to what David has written You may check out the following procedure:

    Code:
    Sub Open_One_Or_Many_Files() 
    Dim vaFiles As Variant 
    Dim i As Long 
    
    vaFiles = Application.GetOpenFilename _ 
             (FileFilter:="Excel Filer (*.xls),*.xls", _ 
             Title:="Open File(s)", MultiSelect:=True) 
     
    If Not IsArray(vaFiles) Then Exit Sub 
    
     With Application 
          .ScreenUpdating = False 
          For i = 1 To UBound(vaFiles) 
             Workbooks.Open vaFiles(i) 
          Next i 
          .ScreenUpdating = True 
    End With 
    
    End Sub
    Kind regards,
    Dennis
    Kind regards,
    Dennis

  4. #4
    Join Date
    Jan 2004
    Location
    San Antonio, TX
    Posts
    2

    Talking Perfect!!

    David/Xl,

    thanks for you help. It was exactly what I needed.

  5. #5
    Join Date
    Jul 2010
    Location
    Chennai
    Posts
    4

    Exclamation MSword VBA .GetOpenFileName

    Hi Dennis,

    I got info from your code, Since I am still new to MSword VBA, when i tried this code in MSWORD (2003), I got "Method or Data Member Not found" error.

    could you please advice

  6. #6
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    511
    Hello,

    Your post is the first on this thread for the last six years!

    The code was written in Excel, not Word. For example, the Word object model does not have a member called Workbooks in <Globals>.

    If you tell us exactly what you are trying to do then we may be able to help.

  7. #7
    Join Date
    Jul 2010
    Location
    Chennai
    Posts
    4

    Cool create macro for converting .txt to .Doc

    Thanks colin,

    I am trying to create a macro for converting *.txt files(anywhere available in hard drive) to *.doc format and store in specific location(Permanent location).

    For this reason i need to add browse tool in my code. Since this was my first macro coding i didnt know the form tools much.. I tried adding miscellaneous keys in toolbox but neither of them doesnt satisfied what i am trying. So i added code given in this forum and added in my code but it is showing "member not found error"... Currently I am using MSword 2003 VBA..

  8. #8
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    511
    Hi,

    The code on this thread is related to opening .CSV files in Excel, using Excel VBA. This thread is in an Excel board.

    The question you have is about converting .TXT files to .DOC files in Word, using Word VBA.

    The code on this thread is not suitable, so you need to remove it from your Word project. My recommendation is that you need to ask your question on a MS Word board or generic VBA board.

    Hope that helps...

  9. #9
    Join Date
    Jul 2010
    Location
    Chennai
    Posts
    4
    Thanks colin

  10. #10
    Join Date
    Aug 2010
    Posts
    1
    Quote Originally Posted by Xl-Dennis View Post
    Hi,

    In addition to what David has written You may check out the following procedure:

    Code:
    Sub Open_One_Or_Many_Files() 
    Dim vaFiles As Variant 
    Dim i As Long 
    
    vaFiles = Application.GetOpenFilename _ 
             (FileFilter:="Excel Filer (*.xls),*.xls", _ 
             Title:="Open File(s)", MultiSelect:=True) 
     
    If Not IsArray(vaFiles) Then Exit Sub 
    
     With Application 
          .ScreenUpdating = False 
          For i = 1 To UBound(vaFiles) 
             Workbooks.Open vaFiles(i) 
          Next i 
          .ScreenUpdating = True 
    End With 
    
    End Sub
    Kind regards,
    Dennis
    I also need this codes. Thanks

  11. #11
    Join Date
    Nov 2010
    Posts
    1

    Red face Code for making two input buttons to browse files.

    Quote Originally Posted by DavidCoutts View Post
    The line of Code you are after to get the openfiledialog box is

    Application.GetOpenFilename

    this will produce the dialog box and then pass a string variable of the path to a variable.

    Ive produced a quick example that will put the path name you select into a text box then when you press ok it will open the workbook

    if it hasnt appeared i will e-mail it to you if you would like it.

    David
    Hey David,
    I also want the same code as I want to compare two xlsm files on some basis. I will input the files from the input box and then store that into a two different text boxes and then compare them. Can you please email me the code for this purpose.Your help will be appreciated.

    Thanks in advance

Posting Permissions

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