Formating cells in Excel

TimTDP

Registered User.
Local time
Today, 07:37
Joined
Oct 24, 2008
Messages
213
I am using Access 2010

I need to format cells inside the Excel spreadsheet

Here is my code
Code:
Dim ApXL As Object
Dim xlWBk As Object
Dim xlWSh As Object
Dim intColumn As Long

Set ApXL = CreateObject("Excel.Application")

ApXL.Application.ScreenUpdating = True
ApXL.Visible = True

Set xlWBk = ApXL.Workbooks.Add

intColumn = 3

xlWSh.Range(Chr(64 + intColumn) & "3:" & Chr(64 + intColumn + 1) & "3").Select
With xlWSh.Selection
       .MergeCells = True
       .HorizontalAlignment = xlCenter
End With
         
xlWBk.Save
xlWBk.Close False
ApXL.Quit
the code "With xlWSh.Selection" returns a run-time error 438 - Object does not support this property or method

Where am I going wrong?

When coding, when entering a "bang" ("."), Access normally returns the next piece of code.
The code above does not!
How to I correct this?
I do have a reference to Microsoft Excel 14.0 Object library

Many thanks in advance
 
Try:

Code:
With xlWSh.Range(Chr(64 + intColumn) & "3:" & Chr(64 + intColumn + 1) & "3")
       .MergeCells = True
       .HorizontalAlignment = xlCenter
End With

Get a result?
 
perfect thanks
 
Just to point out that you don't need to Select anything in Excel in order to format/use it. In fact, the process of selecting it can cause your procedure to run a fraction slower.

The same applies to most applications.
 

Users who are viewing this thread

Back
Top Bottom