Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-15-2022, 05:20 AM
Bikram Bikram is offline Adjusting objects location respective to their anchors Windows 10 Adjusting objects location respective to their anchors Office 2007
Advanced Beginner
Adjusting objects location respective to their anchors
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default Adjusting objects location respective to their anchors

Hi, I have a document where there are floating shapes (text boxes). I wrote the following macro to adjust these text boxes.
Code:
Sub Textbox()

Dim i As Integer
Dim sh As ShapeRange
Set sh = ActiveDocument.Range.ShapeRange
    For i = 1 To ActiveDocument.Shapes.Count
        If sh(i).Type = 17 And sh(i).AutoShapeType = 1 Then
            sh(i).Select
            With Selection.ShapeRange
                .RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
                .RelativeVerticalPosition = wdRelativeVerticalPositionPage
                .RelativeHorizontalSize = wdRelativeHorizontalSizeMargin
                .RelativeVerticalSize = wdRelativeVerticalSizeMargin
                .Left = CentimetersToPoints(1.7)
                .LeftRelative = wdShapePositionRelativeNone
                .TopRelative = wdShapePositionRelativeNone
                .WidthRelative = wdShapeSizeRelativeNone
                .HeightRelative = wdShapeSizeRelativeNone
                .LockAnchor = True
                .TextFrame.WordWrap = True
                .RelativeVerticalPosition =WdRelativeVerticalPosition.wdRelativeVerticalPositionParagraph    
            End With
        End If
     Next
End Sub
It aligns the text boxes to the left of the page, straight from their current position. All my text box's anchors are locked and I was wondering if they could be Horizontally aligned as the above macro does and also align them vertically to the position where they are anchored. I have attached a screenshot, first one is of the original, after running the above macro it looks like the second image, and the third image is the final result I want to achieve.



Thanks,
Bikram
Attached Images
File Type: png Sample.png (86.1 KB, 16 views)
File Type: png Sample 2.png (47.3 KB, 16 views)
File Type: png Sample 3.png (86.3 KB, 18 views)
Reply With Quote
  #2  
Old 06-15-2022, 11:23 PM
Peterson Peterson is offline Adjusting objects location respective to their anchors Windows 10 Adjusting objects location respective to their anchors Office 2019
Competent Performer
 
Join Date: Jan 2017
Posts: 141
Peterson is on a distinguished road
Default

The following code aligns the top edge of each text box to the top of the paragraph to which the text box is anchored:
Code:
Sub Textbox() ' 06/15/2022

    Application.ScreenUpdating = False
    
    Dim i As Integer
    Dim sh As ShapeRange
    
    Set sh = ActiveDocument.Range.ShapeRange
    
    For i = 1 To ActiveDocument.Shapes.Count
        If sh(i).Type = 17 And sh(i).AutoShapeType = 1 Then
            sh(i).Select
            
            With Selection.ShapeRange
                .RelativeHorizontalPosition = wdRelativeHorizontalPositionLeftMarginArea
                
                ' Align shape relative to the paragraph to which it's anchored:
                .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
                
                ' Adjust alignment of the top of the shape to more precisely
                ' align it with the top of the paragraph; revise as necessary:
                .Top = CentimetersToPoints(0.18)
                
                .RelativeHorizontalSize = wdRelativeHorizontalSizeMargin
                .RelativeVerticalSize = wdRelativeVerticalSizeMargin
                .Left = CentimetersToPoints(1.7)
                .LeftRelative = wdShapePositionRelativeNone
                .TopRelative = wdShapePositionRelativeNone
                .WidthRelative = wdShapeSizeRelativeNone
                .HeightRelative = wdShapeSizeRelativeNone
                .LockAnchor = True
                .TextFrame.WordWrap = True
            End With
        End If
    Next
    Application.ScreenUpdating = True
End Sub
Reply With Quote
  #3  
Old 06-16-2022, 05:26 AM
Bikram Bikram is offline Adjusting objects location respective to their anchors Windows 10 Adjusting objects location respective to their anchors Office 2007
Advanced Beginner
Adjusting objects location respective to their anchors
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default

Thank you, peterson..
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping comment anchors colored mstratil Word 2 11-22-2021 09:19 AM
Adjusting objects location respective to their anchors Selecting and deleting all Object Anchors jeffreybrown Word VBA 2 05-06-2016 04:27 AM
Adjusting objects location respective to their anchors Adjusting Header Space and Counter-adjusting another space setting to ensure identical page content cgp1689 Word 3 10-14-2015 07:34 AM
Adjusting objects location respective to their anchors Macros to move objects prevents moving same objects with arrow keys BruceM Word VBA 1 03-10-2015 08:20 AM
Funky connector behavior with newly added anchors koz PowerPoint 0 12-05-2012 01:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft