问题
I am trying to make my column in excel fit into the column size that I give it, I am trying to use the property horizontalAlignment to do this.
I can get it working with xlCenter, but I need to do xlFill but there isn't a value for xlFill.
With objExcelAssist.worksheet.columns("N:N")
.horizontalAlignment = xlCenter
End With
What I have tried:
With objExcelAssist.worksheet.columns("N:N")
.horizontalAlignment = xlFill
End With
With objExcelAssist.worksheet.columns("N:N")
.horizontalAlignment = xlFillDefault
End With
Not had any success so far, am I use the wrong name to fill?
-------------- EDIT ------------------
All shrinkToFit did was make my text smaller

I need it just so it doesn't overlap the next row without effecting the text size
回答1:
Is this what you are trying?
With objExcelAssist.Worksheet.Columns("N:N")
.HorizontalAlignment = xlFill
.ShrinkToFit = True
End With
FYI: The other things that you have at your disposal are
.HorizontalAlignment
.VerticalAlignment
.WrapText
.Orientation
.AddIndent
.IndentLevel
.ShrinkToFit
.ReadingOrder
.MergeCells
EDIT
Followup from comments
The problem finally what I could ascertain is that you are latebinding with MS- Excel and hence MS - Access didn't recognize those constants. You have 2 options in such a case
A. Declare the constants at the top of the code. For example
Const xlFill As Integer = 5
'~~> Other COnstants You can check their values in Excel Object Browser
Const xlBottom As Integer = -4107
Const xlContext As Integer = -5002
Const xlCenter As Integer = -4108
and so on. OR
B. Replace the constants with their values.. For Example
With objExcelAssist.Worksheet.Columns("N:N")
.HorizontalAlignment = 5
.VerticalAlignment = -4107
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = -5002
.MergeCells = False
End With
来源:https://stackoverflow.com/questions/20660557/horizontalalignment-doesnt-work-with-xlfill