VBA: Paste picture from excel to word and WrapSquare picture

Pipe9701

New Member
Joined
Feb 8, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi, I have a code that inserts a text from excel to word, I also pasted a picture to word in the last paragraph, but I need the image to be in WrapSquare format to fit the text, I need to do this repeatedly with the last pasted image as I am going to paste more pictures in the middle of the text, any idea how to do it?

Here is the code:

Sub ExportToWord_Example2()
Dim WordApp As Word.Application
Dim doc As Word.Document
Dim rng As Range

Set WordApp = CreateObject("Word.Application")
With WordApp
.Visible = True
Set doc = .Documents.Add
End With
With doc
.PageSetup.PaperSize = wdPaperA4
End With

For Each rng In Sheet1.UsedRange(1, 1)
With doc.Paragraphs(doc.Paragraphs.Count).Range
.Text = rng.Text
.Font.Bold = rng.Font.Bold
.Font.Color = rng.Font.Color
.ParagraphFormat.LineSpacing = 12
.ParagraphFormat.SpaceAfter = 0
.ParagraphFormat.Alignment = wdAlignParagraphJustify
End With
doc.Range.InsertParagraphAfter
Next rng

Dim rng2 As Word.Range

Set rng2 = doc.Paragraphs.Last.Range

For Each rng In Sheet1.UsedRange(1, 2)
If rng.Value = " Text" Then
With rng2
Worksheets("Sheet2").Shapes("Picture 1").Copy
.Paste
End With
End If
Next rng

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top