Workbook_Open() problems

N

news.microsoft.com

Hi

I'm writing a Workbook_Open() macro to open a text file and read in some
configuration data when an Excel workbook opens:

Private Sub Workbook_Open()
Dim inifile As String
inifile = "c:\test.ini"
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileexists(inifile) Then
Set f = fs.OpenTextFile(inifile, ForReading, TristateFalse)

f.Close
End If
End Sub

It all works perfect until the call to OpenTextFile(..), which generates an
error message:

Run-time error '5':
Invalid procedure call or argument.

I use the FileSystemObject successfully to open files in other macros in the
same workbook,
so I do not understand why it fails here.

Any suggestions..?


Einar Værnes
 
T

Tom Ogilvy

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Private Sub Workbook_Open()
Dim inifile As String
inifile = "c:\test.ini"
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileexists(inifile) Then
Set f = fs.OpenTextFile(inifile, ForReading, False)

f.Close
End If
End Sub
 

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

Top