I wonder if there is any way to align the text inside a cell . Lets say we have inserted data in the cells from A1 down to cell E4. How can one align the text inside those cells using VBA ?
03-09-2006 at 04:30 PM
|
stickleprojects Level: Moderator Registered: 09-09-2002 Posts: 891
Re: Aligning text in cells
Hi,
Use the macro record facility for most of your VBA questions.
Tools/Macros/Record new macro
give it a name
do what you want (ie. select cells, format cell alignment)
stop recording
Now, open the VBA editor and you should see the code in a module.
hope this helps
Kieron
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)
Oh , sorry , my mistake . I meant how can one do that by using VB 6 (not VBA) ?
19-09-2006 at 08:23 PM
|
stickleprojects Level: Moderator Registered: 09-09-2002 Posts: 891
Re: Aligning text in cells
Hi,
I assume you are already using VB6 to pouplate data and create worksheets and stuff, so just record the macro, then paste it into your vb application. Just prefix "ActiveWorksheet" with your application variable.
example:
dim myApp as Excel.Application
dim myWS as Excel.Worksheet
set MyWb = MyApp.ActiveWorksheet
myWb.Range("A1").Format.Align=2
Hope this helps,
Kieron
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)
but I get the message :
"Object does not support this method or property ."
So , I went over and found that you can not use :
ExcelWorksheet.Range("A1:A9").Format ,
becouse the the Format property is not reckognized .
20-09-2006 at 07:18 PM
|
stickleprojects Level: Moderator Registered: 09-09-2002 Posts: 891
Re: Aligning text in cells
Hi,
Did you record the macro in excel as I suggested?
If you had, you would have found the following:
Now , this is a correct code . This one really worked . I guess the first time you were using VB Net instead of VB6 . And , by the way , in order to align text to the center , I used :
ExcelWorksheet.Range("A1:X9").HorizontalAlignment = xlCenter