Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Grrrrr.... can't access Server object ??!!??

OS: W2K SP4
app: Excel 2000

I've written a sub in VBA to read in a file.
This works....
Dim fso As Object
Dim txtstream As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtstream = fso.OpenTextFile("C:\mystuff\tteestfile.txt",
ForReading)

But I don't want to hardcode the fully-pathed filename. So I tried....
Dim fso As Object
Dim txtstream As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtstream =
fso.OpenTextFile(Server.MapPath("tteestfile.txt"), ForReading)
but got an "Object not found" msg on line 4

Then I tried...
Dim fso As Object
Dim txtstream As TextStream
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set txtstream =
fso.OpenTextFile(Server.MapPath("tteestfile.txt"), ForReading)
but this threw an "Object not found" on line 3

Seems like for some reason my script can't "see" Server objects, yet
there are many examples on the web using this syntax. What gives?

The point of all this is to determine the current working directory,
which then is used to build up the fully-pathed filename to stick in
the OpenTextFile method. Help!

TIA,

Steve

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Grrrrr.... can't access Server object ??!!??

The Server object is used in ASP web pages and doesn't
exist in VBA. For the "current working directory", depending
on exactly what you mean by this, you can try CurDir, which
is Excel's "current directory", i.e. where File/Open looks in by
default, or ThisWorkbook.Path, which gives the directory that
contains the workbook that contains the currently-running macro.

So:

fso.OpenTextFile(CurDir & "\tteestfile.txt", ForReading)
or
fso.OpenTextFile(ThisWorkbook.Path & "\tteestfile.txt", ForReading)




wrote:
OS: W2K SP4
app: Excel 2000

I've written a sub in VBA to read in a file.
This works....
Dim fso As Object
Dim txtstream As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtstream = fso.OpenTextFile("C:\mystuff\tteestfile.txt",
ForReading)

But I don't want to hardcode the fully-pathed filename. So I tried....
Dim fso As Object
Dim txtstream As TextStream
Set fso = CreateObject("Scripting.FileSystemObject")
Set txtstream =
fso.OpenTextFile(Server.MapPath("tteestfile.txt"), ForReading)
but got an "Object not found" msg on line 4

Then I tried...
Dim fso As Object
Dim txtstream As TextStream
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set txtstream =
fso.OpenTextFile(Server.MapPath("tteestfile.txt"), ForReading)
but this threw an "Object not found" on line 3

Seems like for some reason my script can't "see" Server objects, yet
there are many examples on the web using this syntax. What gives?

The point of all this is to determine the current working directory,
which then is used to build up the fully-pathed filename to stick in
the OpenTextFile method. Help!

TIA,

Steve


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Grrrrr.... can't access Server object ??!!??

fso.OpenTextFile(CurDir & "\tteestfile.txt", ForReading)

This sorta worked - CurDir didn't return the directory value I
expected.

or
fso.OpenTextFile(ThisWorkbook.Path & "\tteestfile.txt", ForReading)


This worked great! Problem solved. Thanx so much!!

Steve

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
RANK ....Grrrrr Blobbies Excel Discussion (Misc queries) 4 June 29th 09 07:27 AM
c# RTD Server, IRTDUpdate Object heribert Excel Programming 0 April 3rd 06 12:23 AM
Grrrrr OptionTrader Excel Programming 3 November 25th 05 02:33 PM
Creating Worksheet Using Server Object Olivia Towery Excel Worksheet Functions 0 September 6th 05 06:00 PM
Creating Worksheet using Server Object Olivia Towery Excel Worksheet Functions 0 September 6th 05 05:28 PM


All times are GMT +1. The time now is 02:32 AM.

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

About Us

"It's about Microsoft Excel"