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
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