
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