| |
|
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.
|
 |

01-20-04, 23:39
|
|
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?
|
|

01-21-04, 04:51
|
|
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
|
|

01-21-04, 06:26
|
|
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
|
|

01-21-04, 21:17
|
|
Registered User
|
|
Join Date: Jan 2004
Location: San Antonio, TX
Posts: 2
|
|
Perfect!!
David/Xl,
thanks for you help. It was exactly what I needed.
|
|

07-24-10, 09:56
|
|
Registered User
|
|
Join Date: Jul 2010
Location: Chennai
Posts: 4
|
|
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 
|
|

07-24-10, 19:01
|
|
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.
|
|

07-26-10, 08:00
|
|
Registered User
|
|
Join Date: Jul 2010
Location: Chennai
Posts: 4
|
|
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..
|
|

07-26-10, 13:55
|
|
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...
|
|

07-27-10, 03:13
|
|
Registered User
|
|
Join Date: Jul 2010
Location: Chennai
Posts: 4
|
|
|
|

08-03-10, 13:21
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 1
|
|
Quote:
Originally Posted by Xl-Dennis
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-25-10, 22:16
|
|
Registered User
|
|
Join Date: Nov 2010
Posts: 1
|
|
Code for making two input buttons to browse files.
Quote:
Originally Posted by DavidCoutts
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
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|