Get Open File Name

  • Thread starter Thread starter kiza
  • Start date Start date
K

kiza

I am writing a macro in VB but need to open a folder rather than
specific file. As the file is unknown but its location is known.

Is there anyone who could assist me with the GET OPEN FILE NAM
function which will enable me to have a message box from which I ca
choose the relevent file?

Many Thanks In Advance
Kiz
 
I have come up with the following piece of VB Coding but am still havin
a few problems as I cannot open any files with it.

fileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If fileToOpen <> False Then
MsgBox "Open " & fileToOpen
End If

For some reason, I cannot open any files with this coding.

Is there any one who could assist me with this query?
Thank
 
Once you get the name of the file, you have to use:

Workbooks.Open fileToOpen

to actually do the open.

--
Jim Rech
Excel MVP
|I have come up with the following piece of VB Coding but am still having
| a few problems as I cannot open any files with it.
|
| fileToOpen = Application _
| GetOpenFilename("Text Files (*.txt), *.txt")
| If fileToOpen <> False Then
| MsgBox "Open " & fileToOpen
| End If
|
| For some reason, I cannot open any files with this coding.
|
| Is there any one who could assist me with this query?
| Thanks
|
|
| ---
| Message posted
|
 
kiza

I have enclosed the full code for opening a text file using tab as th
column seperator

to change the column seperater to a comma as in a CSV file then chang
Tab:=True to Tab:=False
and Comma:=False to Comma:=True



Sub OpenUserFile()
Dim FileToOpen As Variant

FileToOpen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If FileToOpen = False Then
Exit Sub

End If

MsgBox "Open " & FileToOpen
Workbooks.OpenText FileName:=FileToOpen, Origin:=xlWindows _
, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=Fals
_
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1)

End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top