Julius
Julius

Reputation: 129

Normal open file statement in VBA

I´m trying to open a file but it´s not working.

Workbook.Open C:\users\me\desktop\testfile.txt

I always get the error message: Run-time error '424': Object required

I just want to open a file. It´s not fixed if the file will be a exel, a txt, jpg or word file.

Should be as simple as possible.

Upvotes: 4

Views: 25194

Answers (3)

Sathish Kothandam
Sathish Kothandam

Reputation: 1520

Are you trying to open the text file in excel ..

Then use opentext function

example

Workbooks.OpenText ("C:\users\me\desktop\testfile.txt")

Upvotes: 0

Albert D. Kallal
Albert D. Kallal

Reputation: 48989

To open a word, excel, jpg, pdf or any file, simple use:

Application.FollowHyperlink "path to file name"

Upvotes: 10

Mike
Mike

Reputation: 620

Create an Excel object first:

Dim xl as New Excel.Application

xl.Workbooks.Open("C:\users\me\desktop\testfile.txt")
xl.Visible = True

Upvotes: 0

Related Questions