Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Workbook_Open () Bill Martin Excel Discussion (Misc queries) 12 December 20th 05 05:37 PM
Workbook_Open Jim Zeeb[_2_] Excel Programming 8 December 3rd 04 11:54 PM
workbook_open julio Excel Programming 4 September 26th 04 10:23 PM
Help with Workbook_Open Ruan[_3_] Excel Programming 7 April 28th 04 07:52 AM
Workbook_Open macro created in Excel 97 problems on MAC Dick Kusleika Excel Programming 2 September 8th 03 06:42 PM


All times are GMT +1. The time now is 11:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"