Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-25-2023, 07:29 AM
ctviggen ctviggen is offline Paste in picture, wrap with line, format paragraph before and picture...close to working Windows 10 Paste in picture, wrap with line, format paragraph before and picture...close to working Office 2016
Advanced Beginner
Paste in picture, wrap with line, format paragraph before and picture...close to working
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default Paste in picture, wrap with line, format paragraph before and picture...close to working

I am trying to write a macro to do the following.


Prerequisites: A picture has been copied (using snipping tool); the cursor is at the end of a paragraph.


What I want to do, and what appears to be happening (in parentheses):
1) Mark the current paragraph as "keep with next" (works)

2) Insert a paragraph return/new paragraph (? doesn't seem to work)

3) Paste in the picture (works, but not in a new paragraph - in the paragraph where the cursor was)

4) Format the picture with a line around it (works)
5) Apply a format to the paragraph with the picture (works, but to the wrong paragraph, so the original paragraph is now formatted instead)


This is cobbled together using a recorded macro and information I found online. Since I'm new to VBA, I'm commenting a lot.



Questions:
a) For the "With Selection.ParagraphFormat" inserted by the macro recorder, since all I want is ".KeepWithNext = True", can I remove everything else?
b) Why does my new paragraph for (2) above not seem to work? Or is the "rngSel.Paste" at the wrong spot? Or both?


Sub PastePictureAndCenter()
'
' PastePictureAndCenter Macro
'
' When you insert a picture, it is inserted as an Inline Shape, but you need to select it.
Dim ils As Word.InlineShape
Dim lNrIls As Long
Dim rngDoc As Word.Range
Dim rngSel As Word.Range

Set rngDoc = ActiveDocument.Content
Set rngSel = Selection.Range
rngDoc.End = rngSel.End + 1

' This part from Macro recorder, sets the current paragraph to Keep With Next
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 0


.SpaceBeforeAuto = False
.SpaceAfter = 12
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpace1pt5
.Alignment = wdAlignParagraphLeft
.WidowControl = True
.KeepWithNext = True
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = InchesToPoints(1)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.CollapsedByDefault = False
End With
' This should insert a paragraph
Selection.InsertParagraphAfter
' This was from the macro recorder, but this might replace a selection
' Selection.TypeParagraph
' Another attempt to add a paragraph
' Selection.Paragraphs.Add


' This counts the number of shapes in the document
lNrIls = rngDoc.InlineShapes.Count
'This pastes in the picture
Set rngSel = Selection.Range
rngSel.Paste

' This selects this picture (as an Inline Shape) that was just inserted
Set ils = rngDoc.InlineShapes(lNrIls + 1)
' This wraps the picture with a line
ils.Line.Visible = msoTrue

Selection.Style = ActiveDocument.Styles("OAR Para No Ind for Picture")

End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste in picture, wrap with line, format paragraph before and picture...close to working Wrap Text Inside Picture marconexcel Drawing and Graphics 2 02-02-2018 05:01 PM
Paste in picture, wrap with line, format paragraph before and picture...close to working Wrap TABLES around picture? ShankedS Word Tables 2 11-16-2015 04:27 PM
Paste in picture, wrap with line, format paragraph before and picture...close to working Format Picture toolbar button not working in Word 2007 WaltR Word 2 08-19-2015 05:19 PM
How do you paste a graph from Excel into Word as picture without line appearing? swygant Word 10 07-01-2014 03:23 PM
Paste in picture, wrap with line, format paragraph before and picture...close to working "format picture" - arrows show as no line atop picture marbeth Word 3 07-08-2011 02:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:45 AM.


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