View Single Post
 
Old 03-25-2023, 08:49 AM
ctviggen ctviggen is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default

Wow, thank you so much! I cannot tell you how much time your contribution and this macro saves me. I do these operations over a hundred times, probably into the hundreds of times per year. The same set of (1)-(5) above, over and over... And the macro recorder does not help, as it doesn't work well with inserted pictures.


I took an online class in VBA, got about 3/4 of the way through it, then decided to start writing code to help me and members of my small company with repetitive tasks. The class was great, for providing a foundation, but doesn't answer the specific questions I have.



If anyone does something similar, I just made an addition to add a new paragraph after picture insertion with a different style. Works great.



Code:
Sub PastePictureAndCenter()
    Dim target As Range
    Set target = Selection.Range
    With target
        .ParagraphFormat.KeepWithNext = True
        .InsertParagraphAfter
        .Move wdParagraph
        .Style = ActiveDocument.Styles("OAR Para No Ind for Picture")
        .Paste
        .InlineShapes(1).Line.Visible = msoTrue
        .Move wdParagraph
        .InsertParagraphAfter
        .Style = ActiveDocument.Styles("OAR Para No Ind")
    End With
End Sub
Reply With Quote