
Sub alignGraphicElementToTopRightCornerOfPage()
'
' alignGraphicElementToTopRightCornerOfPage Macro
'
'
Selection.ShapeRange.Align msoAlignTops, True
Selection.ShapeRange.Align msoAlignRights, True
End Sub
Посмотрите разницу между тем, что происходит, когда я использую макрос, и тем, что происходит, когда я вручную выполняю несколько команд из ленты. Я создал макрос, используя функцию записи.
Макрос заставляет элемент исчезать со страницы, что является нежелательным поведением, чего не произошло, когда я записывал макрос.
Почему не работает? Я правильно записал макрос. Есть ли какой-то код vba, который нужно изменить или добавить?
решение1
Я исправил проблему, добавив новые строки для макроса VBA.
Sub alignGraphicElementToTopRightCornerOfPage()
'
' alignGraphicElementToTopRightCornerOfPage Macro
'
'
Selection.ShapeRange.WrapFormat.Type = wdWrapFront
' choose the wrapping type
' the following values are good "3" "wdWrapFront" an "wdWrapTight"
' I don't know what "3" does but Microsoft Office 2007 uses it
Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeHorizontalPositionColumn
Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionPage
Selection.ShapeRange.RelativeHorizontalSize = wdRelativeHorizontalSizePage
Selection.ShapeRange.RelativeVerticalSize = wdRelativeVerticalSizePage
' these commands are needed if the wrapping type is "3" or "wdWrapFront"
' ensure the shape is aligned to the top right corner of the page
' This also fixes the formatting problems when the page has text on it,
' to prevent an extra line break or blank space appearing on the screen
' that the user did not intentionally create
Selection.ShapeRange.WrapFormat.DistanceTop = CentimetersToPoints(0)
Selection.ShapeRange.WrapFormat.DistanceBottom = CentimetersToPoints(0)
' these commands are needed if the wrapping type is "wdWrapTight"
Selection.ShapeRange.Align msoAlignTops, True
Selection.ShapeRange.Align msoAlignRights, True
' start aligning the image to the top right of the page
End Sub