I am trying to center the text in the cells of an Excel spreadsheet through vba coding in Access. Does anyone have<br>any ideas for the properties that can be used for this.<br>Thanks
The best way to get sample code is to record a macro, do what you want the program to do, then modify the code to suit your needs.<br><br>Action:<br>RECORD - select "A2" then hit the ctr text button - STOP<br>Result:<br> Range("A2".Select<br> With Selection<br> .HorizontalAlignment = xlCenter<br> .VerticalAlignment = xlBottom<br> .WrapText = False<br> .Orientation = 0<br> .ShrinkToFit = False<br> .MergeCells = False<br> End With<br><br>Now you can modify this to just change the alignment:<br>Range("A2".HorizontalAlignment = xlCenter<br><br>Hope this helps!<br><br>
Missed the VBA from Access part. You will need to get/create the Excel object then use vba as if you were in Excel. Include MS Excel library in References.<br><br>'Attach to the active Excel object<br>Set xl = GetObject(, "Excel.Application" <br>If xl Is Nothing Then<br> MsgBox "Could Not Attach to Active Excel Object"<br> 'Do Stuff<br>End If<br><br>'Get handle to the active sheet in ExcelSet <br>xlsh = xl.ActiveSheet <br>xlsh.Range("A2".HorizontalAlighment = xlCenter<br>
Thanks for all of the help.<br>This worked real well to cover all<br>of the cells needed.<br><br>For j = 1 To 250<br> xlSheet.Range(
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.