Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Catching an Open Excel File with VBScript

Have you tried using the JET OLE DB provider i.e.

XLconn.ConnectionString = "Source=" & FileName & _
";Extended Properties='Excel 8.0'

--

"nate axtell" <naxtell at progeny dot net wrote in message ...
I'm programming with VBScript and Javascript in an ASP page (NOT .NET).
I am openning an ADO connection with the Excel driver, then recording the
contents of the file to a recordset.

FileName = "path to file..."
Set XLconn = CreateObject("ADODB.Connection")
XLconn.ConnectionString = "DBQ=" & FileName & ";DRIVER={Microsoft Excel
Driver (*.xls)};"
XLconn.Open
XLsql = "SELECT * FROM [Sheet1$]"
Set XLrs = CreateObject("ADODB.Recordset") 'Recreate the recordset
XLrs.cursortype = 3
XLrs.open XLsql, XLconn

'use the rs
'then code to close and set the connection and recordset to Nothing

Here is my dilemma: If the Excel file that I am trying to read is already
open when the web page loads I do not receive any errors. But once the page
is done loading and I close the Excel file, any time I try to open any Excel
file afterwards the grid section will not appear. It is almost as if some
of the drivers get confused because the file was open when made the
connection to it. This doesn't happen if I have other Excel files open when
loading the webpage, only if I have the specific file open that I'm trying
to read. Does anyone know of a way to check if the file is already being
used?
--nate

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Catching an Open Excel File with VBScript

Yes, the the Jet driver gives the same problem.

"onedaywhen" wrote in message
om...
Have you tried using the JET OLE DB provider i.e.

XLconn.ConnectionString = "Source=" & FileName & _
";Extended Properties='Excel 8.0'

--

"nate axtell" <naxtell at progeny dot net wrote in message

...
I'm programming with VBScript and Javascript in an ASP page (NOT .NET).
I am openning an ADO connection with the Excel driver, then recording

the
contents of the file to a recordset.

FileName = "path to file..."
Set XLconn = CreateObject("ADODB.Connection")
XLconn.ConnectionString = "DBQ=" & FileName & ";DRIVER={Microsoft Excel
Driver (*.xls)};"
XLconn.Open
XLsql = "SELECT * FROM [Sheet1$]"
Set XLrs = CreateObject("ADODB.Recordset") 'Recreate the recordset
XLrs.cursortype = 3
XLrs.open XLsql, XLconn

'use the rs
'then code to close and set the connection and recordset to Nothing

Here is my dilemma: If the Excel file that I am trying to read is

already
open when the web page loads I do not receive any errors. But once the

page
is done loading and I close the Excel file, any time I try to open any

Excel
file afterwards the grid section will not appear. It is almost as if

some
of the drivers get confused because the file was open when made the
connection to it. This doesn't happen if I have other Excel files open

when
loading the webpage, only if I have the specific file open that I'm

trying
to read. Does anyone know of a way to check if the file is already

being
used?
--nate



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Catching an Open Excel File with VBScript

The usual way to check this is to try to open the file with exclusive
locking and then ascertain after the event whether you actually *do*
have exclusive locking. This is easy when Excel is automated (e.g.
using VBA Open keyword).

However, I don't know of a reliable way of doing the same using ADO.
You can attempt to get exclusive locks on the connection i.e.

XLconn.Mode = 12 ' adModeShareExclusive

and apparently get it even if the when the workbook is open i.e. no
run-time errors and no ADO errors. You can then open a recordset with
pessimistic locking e.g.

rs.LockType = 2 ' adLockPessimistic

and apparently get that too i.e. no errors.

It's only when you try to do something which requires exclusive
locking that the truth emerges e.g.

XLconn.Execute "CREATE TABLE DropMe (Col1 INT)"

when an error occurs.

--

"nate axtell" <naxtell at progeny dot net wrote in message ...
Yes, the the Jet driver gives the same problem.

"onedaywhen" wrote in message
om...
Have you tried using the JET OLE DB provider i.e.

XLconn.ConnectionString = "Source=" & FileName & _
";Extended Properties='Excel 8.0'

--

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
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
how to convert excle file in csv file in vbscript? Preeti Excel Discussion (Misc queries) 0 July 25th 06 11:37 AM
Can i include a vbscript file with an xml spreadsheet? Neil.Wills Excel Discussion (Misc queries) 0 September 1st 05 12:34 AM
Creating properly formatted text file from vbscript using excel data msnews.microsoft.com[_7_] Excel Programming 2 December 18th 03 09:33 PM
open Excel workbook using vbscript Tom Ogilvy Excel Programming 0 September 16th 03 04:38 PM


All times are GMT +1. The time now is 12:15 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"