View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default VBA From MS Access: Inserting Page Break?

"What's the problem with using Excel constants?"
The problem is you are running the program from Access and
relying on Access to know the value of Excel constants.

One can prepend the application.object to the constant...
SS.xlCalculationManual 'value of -4135

The "With" issue is explained somewhere in that list of reference material
I posted. Using "With" can (but not always) leave an orphan reference
and prevent the Excel application from quitting. Task manager being
the only way to close it. Object references are the way to go.

Jim Cone
http://www.officeletter.com/blink/specialsort.html



"(PeteCresswell)"
wrote in message
Per Jim Cone:
Use an object reference for every object you refer to in Excel.
(that also means do not use ActiveCell, Selection or anything similar)
Do not select anything.
Do not use the "With" construct.
Do not use Excel constants.

So you end up with something like this...
(assumes SS is the Excel application object reference)
Set WS = SS.Worksheets(name)
Set Rng = WS.Rows("20:40")
TargetRow = 11 'Row 30
Rng(TargetRow).PageBreak = -4135 'xlPageBreakManual


Thanks. I never would have figured that out in a million years.

Here's what I wound up going with:
-------------------------------------------------------------------------------
3300 With theSS.Worksheets(theWorkSheetName)
3301 .Rows(myLastTargetRow + 1).PageBreak = xlPageBreakManual
3309 End With
--------------------------------------------------------------------------------

What's the problem with using Excel constants? I'm using them rather
extensively, so maybe my code needs some overhauling.
Something about the needed library not always being present on user's machines?

Ditto "With".... I live and die by it - although I avoid nesting.
Is there some weakness/exposure there?
MS Access 2003...
--
PeteCresswell