ms access 2k automation problem with selection

K

Keith G Hicks

I copied some code from an Excel macro I created into an MS Access 2k
module. Much of it's fine except anything that

Set objActiveWkb = objXL.Application.ActiveWorkbook
With objActiveWkb
Range("A1:G1").Select
With Selection
.HorizontalAlignment = xlCenter <<<<<< ERROR HERE (and all next
lines in this "with")
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End With

I have my reference to Excel 11 set otherwise nothign would work. However,
the "Selection" object appears to have no properties or methods.

Do I need to do this instead (which does compile):

Set objActiveWkb = objXL.Application.ActiveWorkbook
With objActiveWkb
with Range("A1:G1") <<<<<<<< CHANGED LINE (and removed line "with
selection")
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End With


Thanks,

Keith
 
T

Tom Ogilvy

Unless you have created a reference to the excel object model, the constants
you are using are all equal to zero (i.e. undefined to access).

Replace them with the values they represent

? xlcenter
-4108
? xlbottom
-4107
? xlcontext
-5002
 
K

Keith G Hicks

Thanks but xlCenter (and similar) is not the problem (as I said below the
2nd chunk of code compiles fine). The problem is
"Selection.HorizontalAlignment"

"HorizontalAlignment" is not showing up as a property of "Selection"

Keith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top