perola.rike
Board Regular
- Joined
- Nov 10, 2011
- Messages
- 151
I have a WB that exports reports to Word. In this macro, I have a code that finds a specific text (insert table 1 here) in the Word document, and pastes Table 1 at this place. Code 1 inserted below, this is an excerpt from the larger "export from excel to word" code.
However, I would like to copy and paste another Table from another sheet with another range into the same Word document, but I fail to write this code. I tried to duplicate/clone the code below, changed the ranges and text, but it won't work. Code 2 inserted below.
Any tips how to make this work?
Code1
'Paste tables into Word
Set wdRng = wdDoc.Range
With wdRng
'Insert table 1
.Find.ClearFormatting
.Find.Execute FindText:="INSERT TABLE 1 HERE", Forward:=True, Format:=False, Wrap:=wdFindStop
If .Find.Found Then
Call Sheets("Samleprofil").Range("H4:AY28").CopyPicture(xlScreen, xlPicture)
.Paste
End If
Application.CutCopyMode = False
End With
'Insert Table 2
CODE????
Code 2 (this fails)
Set wdRng = wdDoc.Range
With wdRng
.Find.ClearFormatting
.Find.Execute FindText:="ZZZZZ", Forward:=True, Format:=False, Wrap:=wdFindStop
If .Find.Found Then
Call Sheets("WAIS IV Indekser").Range("L1:s16").CopyPicture(xlScreen, xlPicture)
.Paste
End If
Application.CutCopyMode = False
End With
However, I would like to copy and paste another Table from another sheet with another range into the same Word document, but I fail to write this code. I tried to duplicate/clone the code below, changed the ranges and text, but it won't work. Code 2 inserted below.
Any tips how to make this work?
Code1
'Paste tables into Word
Set wdRng = wdDoc.Range
With wdRng
'Insert table 1
.Find.ClearFormatting
.Find.Execute FindText:="INSERT TABLE 1 HERE", Forward:=True, Format:=False, Wrap:=wdFindStop
If .Find.Found Then
Call Sheets("Samleprofil").Range("H4:AY28").CopyPicture(xlScreen, xlPicture)
.Paste
End If
Application.CutCopyMode = False
End With
'Insert Table 2
CODE????
Code 2 (this fails)
Set wdRng = wdDoc.Range
With wdRng
.Find.ClearFormatting
.Find.Execute FindText:="ZZZZZ", Forward:=True, Format:=False, Wrap:=wdFindStop
If .Find.Found Then
Call Sheets("WAIS IV Indekser").Range("L1:s16").CopyPicture(xlScreen, xlPicture)
.Paste
End If
Application.CutCopyMode = False
End With