"Melissa" <mwilliams@snl.comwrote
Quote:
I currently have VBA written to export query results
into an Excel file. That file is then formatted using the
code below. The problem I'm having is that it keeps
throwing Error 91 (Object variable or With block
variable not set) at this part of the code:
Actually, I think the problem here is not "Access VBA" but more to do with
use of the Excel object model and named ranges, and such. I would guess if
you were using VBA in any software to do those Excel object model
manipulations, you'd encounter similar situations.
If you set "Break on all errors", perhaps you could pin it down to a
particular statement.
And, if it only occurs sometime, certainly the logical thing to pursue would
be "What's different about the times when it fails?"
And, as an object that is being tested is the Excel range, it's a good
candidate to be the object that is causing the problem. A debug.print to
display the Range, etc., in the Immediate Window just before executing this
code may (1) get the same error, so you'll have pinned it down to the range
not being properly set on entry or (2) give you some indication of the range
currently chosen and its properties.
Larry Linson
Microsoft Access MVP