Genericfile
Genericfile
Sub ConvertWordToExcelFiles()
On Error GoTo Closesection
Call InitiateLog
Keystrings = Rulesheet.ListObjects("Table1").DataBodyRange.Value
Actiontbl = Rulesheet.ListObjects("Table2").DataBodyRange.Value
strFolderpath = FilesSheet.Range("Folder_path").Text
ExcelBook.Windows(1).Visible = True
ExcelBook.Worksheets("Template").Copy
after:=ExcelBook.Worksheets(ExcelBook.Worksheets.Count)
ExcelBook.Windows(1).Visible = False
ExcelBook.Worksheets(ExcelBook.Worksheets.Count).Name = strExcelSheet
Set ExcelSheet = ExcelBook.Worksheets(strExcelSheet)
Closesection:
oWord.Quit
Set oWord = Nothing
Set oDoc = Nothing
' if new excel file, save & close the current Excel file, Also close the last file
If (strNextExcelfile <> strExcelfile) Or (FileNum = FileList.ListRows.Count) Then
ExcelBook.Save
ExcelBook.Windows(1).Visible = True
ExcelBook.Close
bNewExcelFile = True
Set ExcelBook = Nothing
End If
End If
Next FileNum
End Sub
' ----------------- DECLARATION AND LOADING WORD & EXCEL FILES -------------------
End Sub
Private Sub LogToSheet(ByVal strCategory As String, ByVal strText1 As String)
nLogLine = nLogLine + 1
End Sub
' copy the text to excel row cells from the array
Private Sub AddOutputToXLRow()
For nCol = 1 To 10
ExcelSheet.Cells(nOutputRow, nCol).Value = strOutRowText(nCol)
strOutRowText(nCol) = ""
Next nCol
End Sub
If Len(strStartTxt) = 0 Then
bstartflg = True
End If
Erase strOutRowText()
For Each currPara In oDoc.Paragraphs ' Loop through the paragraphs in the active
document.
' Selects the current paragraph, so that the search is conducted paragraph by
paragraph
Set currRng = oDoc.Range(currPara.Range.Start, currPara.Range.End)
strFirstWord = ""
' strParaText = Trim(Replace(Replace(Replace(currPara.Range.Text, Chr(10), ""),
Chr(13), ""), Chr(9), ""))
strParaText = currPara.Range.Text
' if starting text is not reached, check if is matching with current para
If Not bstartflg Then
If Left(strParaText, Len(strStartTxt)) = strStartTxt Then
Call LogToSheet("Starting text ", 1)
bstartflg = True
End If
End If
bParaProcessed = False
'Match text from list of texts and output to the column
For nCol = 1 To UBound(Keystrings)
If Left(strParaText, Len(Keystrings(nCol, 1))) = Keystrings(nCol, 1) Then
nOutputCol = Keystrings(nCol, 2)
If Keystrings(nCol, 3) = 1 Then
Call AddOutputToXLRow
nOutputRow = nOutputRow + 1
End If
If strOutRowText(nOutputCol) <> "" Then
strOutRowText(nOutputCol) = strOutRowText(nOutputCol) & vbCrLf &
strParaText
Else
strOutRowText(nOutputCol) = strParaText
End If
Call LogToSheet(Keystrings(nCol, 1), strSlokanum)
bParaProcessed = True
bNumberPara = False
Exit For
End If
Next nCol
If bParaProcessed Then
GoTo ContinueNextPara
End If
Case 4: ' if Centered text alignment & bold, consider as sutra & extract x-x-x
as sutra no.
If currPara.Alignment = 1 And currPara.Range.Font.Bold = True Then
If nAlignParaNum = 0 Or nParaCnt - nAlignParaNum > 5 Then
Call AddOutputToXLRow
nOutputRow = nOutputRow + 1 ' move to next row for first sutram
line
nAlignParaNum = nParaCnt
Call LogToSheet("Centered text sutram ", currPara.Alignment)
End If
nOutputCol = Actiontbl(nActn, 2)
If strOutRowText(nOutputCol) <> "" Then
strOutRowText(nOutputCol) = strOutRowText(nOutputCol) & " " &
strParaText
Else
strOutRowText(nOutputCol) = strParaText
End If
bParaProcessed = True
End If
Case 5: 'Bold or normal text starting with number
nPos1 = InStr(1, strParaText, ".")
' In some cases number is not like 234. but 234)
If nPos1 = 0 Or nPos1 > 5 Then
nPos1 = InStr(1, strParaText, ")")
End If
If nPos1 <> 0 Then
strNumb = Left(Trim(strParaText), nPos1 - 1)
nNumber = 0
If IsNumeric(strNumb) Then
nNumber = CDec(strNumb)
End If
' para starts with number for first time. number should be greater than
the sloka count
If nNumber >= nSlokCnt And Not bNumberPara Then
nSlokCnt = nNumber
bNumberPara = True
bParaProcessed = True
If Actiontbl(nActn, 3) = 1 Then
Call AddOutputToXLRow
nOutputRow = nOutputRow + 1
End If
nOutputCol = Actiontbl(nActn, 2)
If strOutRowText(nOutputCol) <> "" Then
strOutRowText(nOutputCol) = strOutRowText(nOutputCol) & " " &
strParaText
Else
strOutRowText(nOutputCol) = strParaText
End If
End If
End If
Case 7: 'number para after number text starting with number and not having
'Moolam'
If bNumberPara Then
bNumberPara = False
bParaProcessed = True
nOutputCol = Actiontbl(nActn, 2)
If strOutRowText(nOutputCol) <> "" Then
strOutRowText(nOutputCol) = strOutRowText(nOutputCol) & " " &
strParaText
Else
strOutRowText(nOutputCol) = strParaText
End If
Call LogToSheet("2nd para starting with number ", strFirstWord)
End If
End Select
ContinueNextPara:
FilesSheet.Range("Status_Value").Value = Str(nParaCnt / TotalParas * 100) & " % "
Next currPara
End Sub
End Function