0

如何为下面的代码对齐(居中)我的单元格值?

For x = 0 To EleXML.ChildNodes.Length - 1    
      Range("A10").offset(x,0) = EleXML.ChildNodes.Item(x).getAttribute("aa")
      Range("A10").offset(x,0) = EleXML.ChildNodes.Item(x).getAttribute("bb")
      Range("A10").offset(x,0) = EleXML.ChildNodes.Item(x).getAttribute("cc")
Next x

请帮助,在此先感谢。

4

1 回答 1

0

是你要找的吗?

s = 1
For x = 0 To EleXML.ChildNodes.Length - 1
    Range("A10").Offset(s, 0) = EleXML.ChildNodes.Item(x).getAttribute("aa")
    Range("A10").Offset(s + 1, 0) = EleXML.ChildNodes.Item(x).getAttribute("bb")
    Range("A10").Offset(s + 2, 0) = EleXML.ChildNodes.Item(x).getAttribute("cc")
    s = s + 3
Next x

您可以通过记录代码来解决这个问题。

Sub Macro1()
'
' Macro1 Macro
'

'
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlRight
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
End Sub

试试这个。您可以根据需要进行调整。

With Range("A10").Offset(x, 0)
    .HorizontalAlignment = xlLeft
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
End With
于 2013-05-29T12:44:19.727 回答