Please help - last hope - Image to word

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.


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]
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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