Consulting

Results 1 to 9 of 9

Thread: Excel Sheets Opens Itself Again After ADO Query !

  1. #1
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    5
    Location

    Exclamation Excel Sheets Opens Itself Again After ADO Query !

    My question is the following:

    - I use VBA in Excel, and would like to use Excel itself as a data source
    (Using ADO). I'd like to keep a table in excel and use SQL expression
    power to manipulate the data in the table (selection, grouping, filtering.),
    rather than using the usual Excel lookups.

    - This does work, but I have an annoying secondary effect with the following
    environment:

    1) I have an (unrelated) excel session already open (Session 1) on my
    Windows desktop.

    2) I open a new, fresh, Excel session (Session2) and open my file, with the
    table, and the VBA code.

    3) I run the code in my file, Session2: it does work, but the unwanted
    effect is that my file opens itself again, as Read-Only, in the other
    Session1!

    I do not know what went wrong. It could be great if you could put me on the
    right tracks.

    Thanks in advance for your help.

    Regards

    Public Sub  Simulation3()
    
        strPathExcelFile_FILTER =  ThisWorkbook.FullName
    
        Set objConnection =  CreateObject("ADODB.Connection")
        Set objRecordSet =  CreateObject("ADODB.Recordset")
    
        objConnection.Open =  "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                             "Data  Source=" & strPathExcelFile_FILTER & ";" &  _
                             "Extended Properties=Excel 8.0;"
    
    
         objRecordSet.Open "SELECT COUNT(*) AS resultat FROM [SHEET1$A1:IV20]
    WHERE  [PX_LAST] > 20", objConnection, adOpenForwardOnly, adLockReadOnly
    
         Simulation.Label2.Caption = objRecordSet.fields("resultat")
    
         objRecordSet.Close
        objConnection.Close
        Set objConnection =  Nothing
        Set objRecordSet = Nothing
    
    End Sub

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Where/how is the extra session created?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    5
    Location

    Exclamation

    Well,

    If you put this procedure inside a module and run it a couple of time. It will open the same file in another excel session in read-only mode.

    I've attached to this post an example.

    Thanks again for ur help.

    Cheers

    Nader

  4. #4
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    5
    Location

    Exclamation

    Well,

    If you put this procedure inside a module and run it a couple of time. It will open the same file in another excel session in read-only mode.

    I've attached to this post an example.

    Thanks again for ur help.

    Cheers

    Nader

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Not here it doesn't.

    Some setting that yu have?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    5
    Location
    Well, I've tried on 6 different pc and it always does it.
    What I do, is simply, open the file inside the first session of excel and I open another one which is empty. It should after I while open the same file on the second session.
    It's really annoying ... I read different post in which people had exactly the same problem as me but they didn't get an answer.
    Thanks

  7. #7
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    What version of Excel is it run under?




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  8. #8
    VBAX Newbie
    Joined
    Aug 2007
    Posts
    5
    Location
    Hello Malik,

    It run under Microsoft Excel 2002 SP3 with XP Pro SP2.

    Thanks for ur help.

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    So you want to query an open Excel workbook, in fact the same workbook, using ADO? How perverse, to go through all of those layers to come back to where you started from.

    Anyway, the answer might lie here http://support.microsoft.com/default...98&Product=xlw
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •