abdelrahman720
New Member
- Joined
- May 10, 2022
- Messages
- 6
- Office Version
- 2016
- Platform
- Windows
Hi all ,
I'm new her , also I'm new at VBA as well
I'm trying to make a excel VBA code copying data (including images) from excel workbook to word template bookmarks
this code should update the word document if opened and open the word document if it's not
so i wrote the following code
it's only copying text data from excel to word bookmarks , but crashes when copy/paste images
also i still need to update the word documents if opened and open it if it's closed
Appreciate your help
I'm new her , also I'm new at VBA as well
I'm trying to make a excel VBA code copying data (including images) from excel workbook to word template bookmarks
this code should update the word document if opened and open the word document if it's not
so i wrote the following code
VBA Code:
Sub VBACODE()
Dim objWord As Object
Dim ws As Worksheet
Set ws = ActiveWorkbook.ActiveSheet
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "WORD TEMPLATE PATH"
With objWord.ActiveDocument
.Bookmarks("Text1").Range.Text = Format(ws.Range("P4").Value, "#,##0.00")
.Bookmarks("Text2").Range.Text = ws.Range("Q4").Value
End With
ws.Range(Array("Picture 1")).CopyPicture
objWord.ActiveDocument.Bookmarks("Pic1").Range.Paste
Set objWord = Nothing
End Sub
it's only copying text data from excel to word bookmarks , but crashes when copy/paste images
also i still need to update the word documents if opened and open it if it's closed
Appreciate your help