If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Using VBA to Create Input Box with Browse Button

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-04, 23:39
dargane dargane is offline
Registered User
 
Join Date: Jan 2004
Location: San Antonio, TX
Posts: 2
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?
Reply With Quote
  #2 (permalink)  
Old 01-21-04, 04:51
DavidCoutts DavidCoutts is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 01-21-04, 06:26
Xl-Dennis Xl-Dennis is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 01-21-04, 21:17
dargane dargane is offline
Registered User
 
Join Date: Jan 2004
Location: San Antonio, TX
Posts: 2
Talking Perfect!!

David/Xl,

thanks for you help. It was exactly what I needed.
Reply With Quote
  #5 (permalink)  
Old 07-24-10, 09:56
kri19081987 kri19081987 is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 07-24-10, 19:01
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
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.
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
  #7 (permalink)  
Old 07-26-10, 08:00
kri19081987 kri19081987 is offline
Registered User
 
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..
Reply With Quote
  #8 (permalink)  
Old 07-26-10, 13:55
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 495
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...
__________________
Colin

RAD Excel Blog

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
  #9 (permalink)  
Old 07-27-10, 03:13
kri19081987 kri19081987 is offline
Registered User
 
Join Date: Jul 2010
Location: Chennai
Posts: 4
Thanks colin
Reply With Quote
  #10 (permalink)  
Old 08-03-10, 13:21
scottpaolucci scottpaolucci is offline
Registered User
 
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
Reply With Quote
  #11 (permalink)  
Old 11-25-10, 22:16
prashantkzha20 prashantkzha20 is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On