Re: testing whether an object exists
From: Ed (Ed_Millis_at_NOSPAM.Hotmail.com)
Date: 05/25/04
- Next message: Tony Proctor: "Re: How can I detect that a program is running on another computer?"
- Previous message: H Leboeuf: "Re: Invalid Page Faults in Kernel32.dll"
- In reply to: Bob Butler: "Re: testing whether an object exists"
- Next in thread: Gale Green: "Re: testing whether an object exists"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 25 May 2004 06:31:14 -0700
Thanks, Bob. This is a lot of stuff for me to wrap my brain around, so I'll
chew on it to get a better grasp. If I can't get it, I'll holler back. But
I really appreciate the time you've spent explaining things.
Ed
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:%23yM%23SveQEHA.620@TK2MSFTNGP10.phx.gbl...
> "Ed" <Ed_Millis@NOSPAM.Hotmail.com> wrote in message
> news:ujYX97dQEHA.3596@tk2msftngp13.phx.gbl
> <cut>
> > I got lost here, though:
> >
> >> 1) trap the error in VB and handle it by releasing the references
> >> you have
> >
> > I thought that's what I was trying to do with IsError. But it raised
> > the error and *didn't* run through the If condition.
>
> If you mean with "Is Nothing" then it may be what you were trying for but
> doesn't work. You'd need to wrap all references to the workbook with
error
> handling
>
> On Error Goto eh
> Set objWS = objWkbk.Sheets("Sheet1")
> <other code>
>
> eh:
> ' clean up (may want to check Err.Number first)
> set objWS=Nothing
> set objWkbk=Nothing
>
>
> > This sounded like a much better option:
> <cut>
> > Right now, I set the objects with:
> > ' Open file
> > Set objXL = CreateObject("Excel.Application")
> > Set objWkbk = objXL.Workbooks.Open(strShell, ReadOnly:=True)
> > objXL.Visible = True
> > Set objWS = objWkbk.Sheets("Sheet1")
> >
> > If I set this object and reference at the module level, then does it
> > replace the objWkbk everywhere else? Or is it addition to it, just
> > set to reference the same workbook?
>
> How you set the references isn't important. How you declare them is. At
> the module level you want:
> Private WithEvents objXL As Excel.Application
> Private WithEvents objWkbk As Excel.Workbook
> Private WithEvents objWS As Excel.Work***
>
> Note that you have to have a reference to Excel to use this method; late
> binding won't work. (You can still use CreateObject though)
>
> --
> Reply to the group so all can participate
> VB.Net... just say "No"
>
- Next message: Tony Proctor: "Re: How can I detect that a program is running on another computer?"
- Previous message: H Leboeuf: "Re: Invalid Page Faults in Kernel32.dll"
- In reply to: Bob Butler: "Re: testing whether an object exists"
- Next in thread: Gale Green: "Re: testing whether an object exists"
- Messages sorted by: [ date ] [ thread ]