+ Reply to Thread
Results 1 to 3 of 3

Workbook connections count issue

  1. #1
    Registered User
    Join Date
    04-27-2010
    Location
    Louisville KY USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Workbook connections count issue

    I have the following code. I want to check for any ODBC or other connections and ask the user if they want to refresh when the file opens. In the debugging MsgBoxes that I have below the ThisWorkbook.Connections.Count is 0. The Len(Trim(.....)) never shows up. I then get the "This workbook contains" MsgBox. My guess is that if there are truly no connections then Connections(1) doesn't exist and throws an exception. However, if that's the case, how is it making it into the If block? ThisWorkbook.Connections.Count is 0. We've already established that through the first MsgBox. Confused.

    Thanks!

    Please Login or Register  to view this content.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,281

    Re: Workbook connections count issue

    Hi mateoc15,

    I think you get into your If section of code because you have an "On Error Resume Next" line.
    The Connections(1) part gives the error and it simply continues onto the next line.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    04-27-2010
    Location
    Louisville KY USA
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Workbook connections count issue

    Ok, so I've read that the On Error Resume Next is dangerous and clearly it has screwed me here. Maybe someone can explain the best way to handle this exception?

    In every other programming language I've ever used if the first statement evaluates to false in an "And" statement then the second one is never even checked (thus no exception thrown). If, as in my example, the count is 0 then shouldn't that entire If block be skipped or does VBA evaluate all of the If conditions and THEN make the decision?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1