Sub Main()
ufWord.Show
End Sub
Function LinesToArr(s As String, dPoints As Double, _
Optional wFile As String = "")
Dim a(), strLine As String, i As Long, L As Long
'Tools > References > Microsoft Word xx.0 Object Library
Dim wdApp As Word.Application, myDoc As Word.Document
Dim wClose As Boolean
If wFile = "" Then wFile = ThisWorkbook.Path & "\LinesToArray.docm"
'Tell user what file is missing and exit.
If Dir(wFile) = "" Then
MsgBox "File does not exist." & vbLf & wFile, _
vbCritical, "Exit - Missing LinesToArray File"
End If
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
wClose = True
End If
On Error GoTo 0
'On Error GoTo errorHandler
With wdApp
.Application.DisplayAlerts = wdAlertsNone
'Open form file and associate data file
Set myDoc = wdApp.Documents.Open(wFile, Visible:=True)
With myDoc
.Content = s
With wdApp.Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
'9.6 = 1" in LinesToArray.docm
.RightIndent = InchesToPoints(10.6 - dPoints / 72)
End With
L = .BuiltinDocumentProperties("Number of Lines")
End With
With wdApp.Selection
.HomeKey Unit:=wdStory
Do
.EndKey Unit:=wdLine, Extend:=wdExtend
ReDim Preserve a(0 To i)
a(i) = .Text
.MoveDown Unit:=wdLine, Count:=1
.HomeKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1
i = i + 1
Loop Until i = L
End With
.Application.DisplayAlerts = wdAlertsAll
myDoc.Close False
Set myDoc = Nothing
If wClose Then Set wdApp = Nothing
End With
GoTo EndNow
errorHandler:
MsgBox "Unexpected error: " & Err.Number & vbLf & Err.Description
EndNow:
'Trim trailing chars in last element if it exists.
s = a(UBound(a))
'If Right(s, 2) = vbNewLine Then a(UBound(a)) = Left(s, Len(s) - 2)
If Right(s, 1) = vbCr Then a(UBound(a)) = Left(s, Len(s) - 1)
LinesToArr = a
End Function