View Single Post
 
Old 03-25-2023, 07:54 AM
Italophile Italophile is offline Windows 11 Office 2021
Expert
 
Join Date: Mar 2022
Posts: 538
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

When you record a macro you will get a lot of code that you don't need. That code can safely be deleted.

As you didn't move the selection after adding the new paragraph your subsequent code was executed on the original selection.

When you post code in a question here you need to use the code format button (#)

The only code you actually need is below.

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
    End With
End Sub
Reply With Quote