Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 -- Regards, Tom Ogilvy "news.microsoft.com" wrote in message ... 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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Workbook_Open () | Excel Discussion (Misc queries) | |||
Workbook_Open | Excel Programming | |||
workbook_open | Excel Programming | |||
Help with Workbook_Open | Excel Programming | |||
Workbook_Open macro created in Excel 97 problems on MAC | Excel Programming |