chooriang
08-29-2017, 07:57 PM
It's mac OS.
I'm trying to copy paste a picture from Excel to Word document.
The picture should go to the specified bookmark location but unfortunately, it won't.
The code works just fine on windows but not in Mac.
I can't find a flaw on it.
Perhaps somebody could help me to solve this.
Thanks in advance.
Here is the current code:
Sub FindMeReplaceMe()
Dim wdApp As Object
Dim wdDoc As Object
Dim wdRng As Object
Dim BmkRng As Object 'Word.Range
Dim myWkb As Workbook
Dim myWks As Worksheet
Dim myShp As Shape
Set myWkb = ThisWorkbook
Set myWks = myWkb.Sheets("Sheet1")
On Error Resume Next
Set wdApp = GetObject(, "Word.application") 'gives error 429 if Word is not open
If Err = 429 Then
Set wdApp = CreateObject("Word.application") 'creates a Word application
Err.Clear
End If
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(strOutputFile)
Set myShp = Nothing
On Error Resume Next
Set myShp = myWks.Shapes("HeaderImage")
On Error GoTo 0
If Not myShp Is Nothing Then
With wdDoc
If .Bookmarks.Exists("theHeaderImage") Then
Set BmkRng = .Bookmarks("theHeaderImage").Range
myWks.Shapes("HeaderImage").Copy
BmkRng.PasteAndFormat (wdPasteDefault)
DoEvents
Else
MsgBox "Bookmark of ""theHeaderImage"" is not found", vbExclamation
End If
End With
Else
MsgBox "Header image is not exist", vbExclamation
End If
Set wdApp = Nothing: Set wdDoc = Nothing: Set wdRng = Nothing
End Sub
I'm trying to copy paste a picture from Excel to Word document.
The picture should go to the specified bookmark location but unfortunately, it won't.
The code works just fine on windows but not in Mac.
I can't find a flaw on it.
Perhaps somebody could help me to solve this.
Thanks in advance.
Here is the current code:
Sub FindMeReplaceMe()
Dim wdApp As Object
Dim wdDoc As Object
Dim wdRng As Object
Dim BmkRng As Object 'Word.Range
Dim myWkb As Workbook
Dim myWks As Worksheet
Dim myShp As Shape
Set myWkb = ThisWorkbook
Set myWks = myWkb.Sheets("Sheet1")
On Error Resume Next
Set wdApp = GetObject(, "Word.application") 'gives error 429 if Word is not open
If Err = 429 Then
Set wdApp = CreateObject("Word.application") 'creates a Word application
Err.Clear
End If
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open(strOutputFile)
Set myShp = Nothing
On Error Resume Next
Set myShp = myWks.Shapes("HeaderImage")
On Error GoTo 0
If Not myShp Is Nothing Then
With wdDoc
If .Bookmarks.Exists("theHeaderImage") Then
Set BmkRng = .Bookmarks("theHeaderImage").Range
myWks.Shapes("HeaderImage").Copy
BmkRng.PasteAndFormat (wdPasteDefault)
DoEvents
Else
MsgBox "Bookmark of ""theHeaderImage"" is not found", vbExclamation
End If
End With
Else
MsgBox "Header image is not exist", vbExclamation
End If
Set wdApp = Nothing: Set wdDoc = Nothing: Set wdRng = Nothing
End Sub