RBLearning
New Member
- Joined
- Feb 18, 2019
- Messages
- 1
Hi all I know it's my first post so please forgive me but I am in need of some help.
I have been working on the code below and it's driving me insane. I'm trying to copy an image from 'Sheet1' (users) cell 45 and paste into a word a document table (iii), but it's just left blank - everything else is working well, the only thing that's not working is the image file. Can anyone shed any light as to what I'm doing wrong? I've tried copy and paste object but I just get errors!
I'm using ImgPath which is placed in cell 44 and the image is copied and pasted in to cell 45 (that's all working great).
Thanks in advance.
I have been working on the code below and it's driving me insane. I'm trying to copy an image from 'Sheet1' (users) cell 45 and paste into a word a document table (iii), but it's just left blank - everything else is working well, the only thing that's not working is the image file. Can anyone shed any light as to what I'm doing wrong? I've tried copy and paste object but I just get errors!
I'm using ImgPath which is placed in cell 44 and the image is copied and pasted in to cell 45 (that's all working great).
Thanks in advance.
Code:
[COLOR=#252C2F][FONT=Helvetica]
Private Sub PrintUserBtn_Click()
Dim numberOfStaff As Long
numberOfStaff = Me.lbResList.ListCount 'CountItems
If numberOfStaff = 0 Then Exit Sub
Dim wdApp As Object, wdDoc As Object, x
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open("I:\Details.docx")
wdApp.Visible = True
With wdDoc.Content.Find
.Execute FindText:="AAA", ReplaceWith:=Me.lbResList.List(0, 4), Replace:=wdReplaceAll 'Title
.Execute FindText:="BBB", ReplaceWith:=Me.lbResList.List(0, 1), Replace:=wdReplaceAll 'First Name
.Execute FindText:="ccc", ReplaceWith:=Me.lbResList.List(0, 5), Replace:=wdReplaceAll 'Surname
.Execute FindText:="ddd", ReplaceWith:=Format(DateofBirth, "DD/MM/YYYY"), Replace:=wdReplaceAll 'Date of Birth
.Execute FindText:="eee", ReplaceWith:=Me.lbResList.List(0, 7), Replace:=wdReplaceAll 'Email
.Execute FindText:="fff", ReplaceWith:=Format(EnrolmentDate, "DD/MM/YYYY"), Replace:=wdReplaceAll 'Register Date
.Execute FindText:="ggg", ReplaceWith:=Me.lbResList.List(0, 37), Replace:=wdReplaceAll 'Mailing List
.Execute FindText:="hhh", ReplaceWith:=Me.lbResList.List(0, 36), Replace:=wdReplaceAll 'Notes
.Execute FindText:="iii", ReplaceWith:=Me.lbResList.List(0, 45), Replace:=wdReplaceAll 'Image
End With
wdApp.DisplayAlerts = False
x = "" & StaffName.Value & " Details.docx"
'wdDoc.SaveAs (x)
Set wdApp = Nothing: Set wdDoc = Nothing
End Sub[/FONT][/COLOR]