R
RB Smissaert
Doing a mailmerge from Excel with Word automation.
I am altering a document and then doing SaveAs.
This runs in a loop and after doing SaveAs I need the original document to
do the same again.
Rather than closing and reopening this document I prefer to keep the text +
formatting in a range
variable and putting that back. Only reason for this is that is quicker.
This is the simplified code I have:
Dim wd As Object
'need to add Word here as there also is a DAO Document!
Dim Doc As Word.Document
Dim rngAllText As Word.Range
Set wd = CreateObject("Word.Application")
Set Doc = wd.Documents.Open(strLetterDoc)
Set rngAllText = Doc.Content.FormattedText.Duplicate
'alter the document here
'do SaveAs here
Doc.Content.FormattedText = rngAllText
At this line line I get error 5937:
Cannot copy content between these 2 ranges.
Thanks for any advice in this.
RBS
I am altering a document and then doing SaveAs.
This runs in a loop and after doing SaveAs I need the original document to
do the same again.
Rather than closing and reopening this document I prefer to keep the text +
formatting in a range
variable and putting that back. Only reason for this is that is quicker.
This is the simplified code I have:
Dim wd As Object
'need to add Word here as there also is a DAO Document!
Dim Doc As Word.Document
Dim rngAllText As Word.Range
Set wd = CreateObject("Word.Application")
Set Doc = wd.Documents.Open(strLetterDoc)
Set rngAllText = Doc.Content.FormattedText.Duplicate
'alter the document here
'do SaveAs here
Doc.Content.FormattedText = rngAllText
At this line line I get error 5937:
Cannot copy content between these 2 ranges.
Thanks for any advice in this.
RBS