Bryce Bassett
asked on
Word VBA: Copy contents of one rich text content control to another without losing formatting?
I'm using Word 2010. Trying to use Word VBA to copy the contents of one rich text content control to another rich text content control in a second document. Using this method below. But the destination CC does not retain the formatting (specifically list numbering, bold, italics) that were in the source CC.
Do I need to be using a different method to accomplish this without losing the formatting?
Thanks!
TargetReport.SelectContentControlsByTitle("Materials").Item(1).Range.Text = _
SourceProtocol.SelectContentControlsByTitle("Materials").Item(1).Range.Text
Below is the result I get.Do I need to be using a different method to accomplish this without losing the formatting?
Thanks!
That is fine, attempt 1 just sets the text, not the text attributes
The only reason to avoid copy paste is if you don't want to smite the clipboard, so might not be popular if you are giving to others to use. Fine for personal use though
ASKER
Well, this is in fact for client use, so if there's a way to avoid the clipboard that would be nice.
I can save a couple lines by shortening to:
Is there a direct way to copy and paste in one statement without using the clipboard? For example, I've used this method in Excel, and assumed this does not use the clipboard, but maybe I'm wrong:
I can save a couple lines by shortening to:
SourceProtocol.SelectContentControlsByTitle("Methods").Item(1).Range.Copy
TargetReport.SelectContentControlsByTitle("Methods").Item(1).Range.Paste
But this still uses the clipboard, doesn't it? Is there a direct way to copy and paste in one statement without using the clipboard? For example, I've used this method in Excel, and assumed this does not use the clipboard, but maybe I'm wrong:
mySheet.Range("A1:D4").Copy Destination:= mySheet.Range("E5")
Any other thoughts would be appreciated. Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can use something like this to clear the clipboard...
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Sub EmptyClip()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
End Sub
ASKER
Didn't really answer my question. I don't need to bother with a custom clipboard.
ASKER
Open in new window
Any reason I can't just do it this way? Is there a more robust method?