ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Workbook_Open() problems (https://www.excelbanter.com/excel-programming/322907-workbook_open-problems.html)

news.microsoft.com[_7_]

Workbook_Open() problems
 
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



Tom Ogilvy

Workbook_Open() problems
 

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






All times are GMT +1. The time now is 12:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com