PDA

View Full Version : Insert Image to Specific Page using APPWD



psctornado
09-15-2014, 10:11 AM
Hi All,

Hope your all having a great day. I need a little help on inserting an image on a specific page. Currently I have image 'Dog' inserting where it should, at the top of the document of the 1st page. However, I would like to have the image 'Cat' be inserted after my 'Page Break' code. Instead what my code seems to be doing is inserting both 'Dog' & 'Cat' in the same page and same row.

Would anyone be able to help. Below is an abbreviated code from my workbook.


D104 = Cat
B5 = Dog

Any help would be greatly appreciated!!

Thanks!!!!!



Private Sub cmdTrigLitAP_Click()
Dim appWD As Word.Application
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
' Tell Word to create a new document
appWD.Documents.Add
' Document entered
appWD.Selection.Font.Size = 11
appWD.Selection.Font.Name = "Times New Roman"
appWD.Selection.PageSetup.TopMargin = InchesToPoints(1)
appWD.Selection.PageSetup.LeftMargin = InchesToPoints(1)
appWD.Selection.PageSetup.RightMargin = InchesToPoints(1)
With appWD.Selection.ParagraphFormat
.RightIndent = InchesToPoints(0)
.LeftIndent = InchesToPoints(0)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
If (Dir("I:\Dog.jpg") = "") Then
FileCopy "C:\\Users\Documents\Dog.jpg", "I:\Dog.jpg"
End If
appWD.Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
appWD.Selection.Font.Bold = True
appWD.Selection.TypeText Text:=Sheet15.Range("AB1")
appWD.Selection.TypeParagraph
appWD.Selection.Font.Bold = False
appWD.Selection.TypeText Text:=Sheet15.Range("AB2")
appWD.Selection.TypeParagraph
appWD.Selection.TypeText Text:=Sheet15.Range("AB3")
appWD.Selection.TypeParagraph
appWD.Selection.Font.Bold = True
appWD.Selection.TypeText Text:=Sheet15.Range("AB4")
appWD.Selection.TypeParagraph
appWD.Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
appWD.Selection.TypeText Text:=Sheet15.Range("A7")
appWD.Selection.TypeParagraph
appWD.Selection.TypeText Text:=Sheet15.Range("A8")
appWD.Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(6.25), _
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
appWD.Selection.TypeText Text:=vbTab & Sheet15.Range("V9")
appWD.Selection.TypeParagraph
appWD.Selection.InsertBreak Type:=wdPageBreak
If (Dir("I:\About.jpg") = "") Then
FileCopy "C:Users\Documents\Cat.JPG.jpg", "I:\Cat.jpg"
End If
appWD.Selection.TypeParagraph
appWD.Selection.TypeText Text:=Sheet15.Range("A60")
appWD.Selection.TypeParagraph
appWD.ActiveDocument.Shapes.AddPicture "I:\" & Sheet11.Range("D104") & ".jpg", False, True, 0, 0
appWD.ActiveDocument.Shapes.AddPicture "I:\" & Sheet11.Range("B5") & ".jpg", False, True, 0, 0
End Sub

snb
09-15-2014, 11:53 AM
Sub M_snb()
With CreateObject("word.document")
.Content = String(5, vbCr)
.Content.insertbreak
.Paragraphs(1).Range.InlineShapes.AddPicture "G:\Mijn afbeeldingen\peer.jpg", False, True
.Content.InsertAfter vbCr
.Paragraphs.last.Range.InlineShapes.AddPicture "G:\Mijn afbeeldingen\sinaasappel.jpg", False, True
End With
End Sub

psctornado
09-15-2014, 12:19 PM
Hi SNB,

Hope all is well. I tried fitting your code with mine, and it doesn't seem to be working with it. Could you explain it a bit?

Thanks!

snb
09-15-2014, 02:38 PM
The code is meant to replace your code completely.
The only thing you have to do is adapting the fullname of the pictures and run the code.