Results 1 to 2 of 2
2006-03-23, 18:47 #1
- Join Date
- Mar 2003
- Elkins Park, Pennsylvania, USA
- Thanked 0 Times in 0 Posts
Prevent Pasting Multiple Sections (Word XP VBA)
Pardon me if I missed a similar post, but I didn't find anything about this topic when I searched.
I have a type of document wherein I'd like to prevent people from pasting text containing multiple sections. Currently, I hijacked the EditPaste command and check to see if what was just pasted is more than one section. If so, I highlight it and delete it. What I would like, though, would be a more elegant solution that would (hopefully) check the contents while it's on the clipboard. My reasoning is that, even though I'm able to select and delete what was pasted, I'm never sure that the document's headers, layout, and general integrity would be the same once the clipboard contents have actually been part of the document. I can't do an undo, and I'm not quite sure why. I'm pasting that snippit of my code here, so if it's a simple matter of where I place the undo, I'd be happy with that, too.
origSectionCount = ActiveDocument.Sections.Count
Set PasteRange = Selection.Range
'check to see if the user pasted multiple sections...
newSectionCount = ActiveDocument.Sections.Count
If newSectionCount > origSectionCount Then 'if multiple sections were introduced...
If MsgBox("The text you are pasting contains" & Str(newSectionCount - origSectionCount) & " section breaks. " _
& "These section breaks will probably change the document's headers, footers, page-layout, etc., and will require additional formatting by RDS " _
& "to correct it." & vbCrLf & vbCrLf & "Do you really want to change the format of the protocol by pasting multiple sections " _
& "into it?", vbExclamation + vbYesNo, "Protocol Section Change") = vbNo Then
MsgBox "Please paste text into this Procotol one section at a time, and do not include section breaks.", vbInformation + vbOKOnly _
, "Protocol Format"
Else 'if the user insists on keeping multiple sections...
Does anyone have any experience with this sort of thing, and can it be done?<font face="Comic Sans MS">That's what you do in a herd; you look out for each other!</font face=comic> - Mike
2006-03-23, 22:15 #2
- Join Date
- Mar 2002
- Thanked 25 Times in 25 Posts
Re: Prevent Pasting Multiple Sections (Word XP VBA)
Perhaps you could add a new, invisible document:
Dim doc As Document
Set doc = Documents.Add(Visible:=False)
and paste into this document, then count the number of sections. Don't paste into the original document if there is more than one section. You can discard the new document without saving.