Forum Discussion
qazzzlyt
Jul 21, 2024Copper Contributor
Fastest way to read entire Word text to array
ReDim arr(1 To wdDoc.Paragraphs.Count)
For i = 1 To wdDoc.Paragraphs.Count
arr(i) = wdDoc.Paragraphs(i).Range
Next i
I got above code to read all Word text to a array. It's very slow. What is the most efficient way? I guess even copy/paste in VBA would be faster, but I think there should be a better way.
Thanks in advance.
Without looping:
arr = Split(wdDoc.Content, vbCr)
Keep in mind that
1) Split returns a zero-based array. The first paragraph is arr(0).
2) The elements of arr do not include the paragraph mark, unlike in your method.
- qazzzlytCopper Contributor
HansVogelaar thank you! This is exactly what I am looking for!