fcqmax
asked on
VBA Macro Help: Copy/Filtering Selection.Range.XML to Clipboard
Currenly I'm using this code to copy WordML to clipboard in Word 2003:
Sub copyXMLToClipboard()
Dim DataObj As New MSForms.DataObject
Dim S As String
S = Selection.Range.XML
DataObj.SetText S
DataObj.PutInClipboard
End Sub
But I found out that it is copying too much info into the clipboard, I would like to limit the copy selection to only the content within the <wx:sect></wx:sect> tags and nothing else.
Here's an example, if Selection.Range.XML has the following content:
<w:wordDocument>
<o:DocumentProperties>
...XML content here...
</o:DocumentProperties>
<w:fonts>
...XML content here...
</w:fonts>
<w:body>
<wx:sect>
<w:p>
...My XML content here...
</w:p>
<w:p>
...My XML content here...
</w:p>
</wx:sect>
</w:body>
</w:wordDocument>
What I'd like is a macro which copies Selection.Range.XML into a variable, strips out everything I don't want. And the resulting XML in the clipboard should be:
<w:p>
...My XML content here...
</w:p>
<w:p>
...My XML content here...
</w:p>
Sub copyXMLToClipboard()
Dim DataObj As New MSForms.DataObject
Dim S As String
S = Selection.Range.XML
DataObj.SetText S
DataObj.PutInClipboard
End Sub
But I found out that it is copying too much info into the clipboard, I would like to limit the copy selection to only the content within the <wx:sect></wx:sect> tags and nothing else.
Here's an example, if Selection.Range.XML has the following content:
<w:wordDocument>
<o:DocumentProperties>
...XML content here...
</o:DocumentProperties>
<w:fonts>
...XML content here...
</w:fonts>
<w:body>
<wx:sect>
<w:p>
...My XML content here...
</w:p>
<w:p>
...My XML content here...
</w:p>
</wx:sect>
</w:body>
</w:wordDocument>
What I'd like is a macro which copies Selection.Range.XML into a variable, strips out everything I don't want. And the resulting XML in the clipboard should be:
<w:p>
...My XML content here...
</w:p>
<w:p>
...My XML content here...
</w:p>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, I had to change integer to long for it to work in my situation
ASKER
-- Error Dialog --
Run-time error '6';
Overflow
------------------
startPos = InStr(S, StartTag) <-- This line is highlighted