VBA code to open file?

  • Thread starter Thread starter pgoodale
  • Start date Start date
P

pgoodale

Does anyone know the line of code to open a file? I have created a macro
and am programming in VBA. All I need is the code which opens up files.
Any help is really appreciated.
 
If You want to open an excel file use this:
Workbooks.Open file_name

text file in Excel:
Workbooks.OpenText file_name
for example:
Workbooks.OpenText filename:="DATA.TXT", _
dataType:=xlDelimited, tab:=True


if it is a text file and You want to read from it:
Open file_name For Input As #1

write to a file
Open file_name For Output As #1

Read the online help for open method to get more info
 
You simply want to open a workbook?

Workbooks.Open "path"

or something completely different, like a word file?

Sub StartWinWord()
Dim RetVal
RetVal = Shell("C:\Program Files\Microsoft _
Office\Office10\WinWord.exe c:\boot.ini", 1)

End Sub
 
Use the macro recorder to create the code you need, it is far simpler than
trying to work out the intricacies of writing the code directly, especially
for simple code.

Cheers
N
 
You could have posted your code for comments and suggestions. Or, you could
have looked in vba HELP index for OPEN
We help those who help themselves.
 
Back
Top