Justify Data in Excel using Access-TJ

  • Thread starter Thread starter ambushsinger
  • Start date Start date
A

ambushsinger

I'm trying to select particular cells in an Excel worksheet from Access and
center or right justify them.
any ideas?
 
The way to do it (by cheating) is to open Excel and record a macro in which
you select the cells and then justify them. Then open the VBA Editor in Excel
and copy the code over to Access.

Are you able to open the Excel spreadsheet using VBA? The macro will give
you the code to select & format, but you'll need additional code to actually
open up the file.
 
When the worksheet opens there are other macros that run. Can I call the
macro name from Access such as: xl.run "justify" ?
 
Hi ambushsinger,
for example to center (or right align) the content of cells J1 to K2

Set ExcelSheet = CreateObject("Excel.Sheet")
ExcelSheet.Application.Range("J1:K2").Select
With ExcelSheet.Application.Selection
.HorizontalAlignment = xlCenter ''to center horizontally
.HorizontalAlignment = xlRight ''to right align
.VerticalAlignment = xlCenter ''to center vertically

end with

HTH Paolo
 
Thank you Paolo...exactly what i needed.

TJ

Paolo said:
Hi ambushsinger,
for example to center (or right align) the content of cells J1 to K2

Set ExcelSheet = CreateObject("Excel.Sheet")
ExcelSheet.Application.Range("J1:K2").Select
With ExcelSheet.Application.Selection
.HorizontalAlignment = xlCenter ''to center horizontally
.HorizontalAlignment = xlRight ''to right align
.VerticalAlignment = xlCenter ''to center vertically

end with

HTH Paolo
 
Back
Top