I'm loving this. But stuck at the next step.
I have grabbed the 8,500+ paragraphs in a 411 page document (with Crystal's
code from here) and stuck them in an Access table via ADO and SQL. It was fairly quick, incidentally. Works great.
I now use this to get the data from that table and loop through the recordset and dump them on a blank Word document. That works great too. (My expertise is in Excel/ADO/SQL. I was surprised to be able to adapt it to Word VBA quite easily. (I'm a Word VBA baby).
Here's my next step. I hope the experts will nudge me in the right direction.
Another field in the recordset retrieved is "Style", which is right there and available on each iteration of the loop (Whoopie!). That is rsData.Fields.Item("Style"
It should be easy (but not for me) to apply that style to the text that the loop has just pasted.
, I see that the range rngNew is always from the 'top the document to the current end point'. This is not the range I want. I want the text paragraph that's just been inserted.
(hmmm .. that would be the last paragraph on each iteration)
Thanks for just a hint. I've learned so much in a week. (The Word object model is sooooo different to Excel's. Naturally)
Running this in Word 2016. Takes about 10 seconds for 8,500+ paragraphs on about 400 pages.
Dim rsData As ADODB.Recordset
Dim sSQL As String
Dim docActive As Document
Dim rngNew As Range
Dim dteStart As Date
Dim dteEnd As Date
Application.ScreenUpdating = False
Set docActive = ThisDocument
Set rngNew = docActive.Range
dteStart = Now
sSQL = "SELECT * FROM tblParagraphs WHERE SectionNumber >= 5"
Set rsData = New ADODB.Recordset
rsData.Open sSQL, objConn, adOpenForwardOnly, adLockReadOnly, adCmdText
If Not rsData.EOF Then
Do Until rsData.EOF
If rsData.Fields.Item("SectionNumber").Value >= 5 Then
rngNew.InsertAfter Text:=rsData.Fields.Item("ParagraphText").Value & vbCr
'rngNew.Select 'commented out. This is for examamining what rngNew is
Application.ScreenUpdating = True
'to see how long it took
dteEnd = Now
rngNew.InsertAfter Text:=dteStart & vbCr
Crystal's code is here