I am trying to write a VBA script to help me with some repetitive operations in a larger Word document. As part of this I need to know how many paragraphs are in a piece of text copied from another word document into the clipboard. (The steps that follow in my intended procedure depend on the paragraph counts.)
I tried this (see below), but got stuck with my approach, as easily visible from my comments in the script:
Sub InsertMultiPara()
'Declarations
Dim MyData As MSForms.DataObject
Dim intNumPara As Integer
Dim strClip As Variant
'Fill them
Set MyData = New MSForms.DataObject
MyData.GetFromClipboard
strClip = MyData.GetText
'Continuing my ideas... various experiments
'OFF intNumPara = MyData.Paragraphs.Count
'Error: "Object dosn'nt support this property or method"
'OFF intNumPara = strClip.Paragraphs.Count
'Error: "Object required"
'Paste the Clipboard content
Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
'Expand selection to everything just pasted:
Selection.MoveUp Unit:=wdParagraph, Count:=intNumPara, Extend:=wdExtend
'Do some other stuff with that range
Application.Run MacroName:="Normal.MyMacros.Something-nice-and-useful"
End Sub
But, as you see in the comments underneath the 'OFF commented lines: this does not work as I thought it would.
So, actually simple question: how can I implement a pragraph count on stuff that sits in the clipboard (and definitely has paragraphs, as they are there when the clipboard content is pasted).
Paragraphs.Count
on that content, delete the content, paste to the "real" document. That, or the code needs to get the pasted content after-the-fact. - Cindy Meister