Public Const constStrMenuCmdInNGB As String = “MenuCmdInNGB”
‘Public Const constStrNGBSpecDoc As String = “forTest__NGBFunctionalSpec.doc”
Public Const constStrNGBSpecDoc As String = “NGBFunctionalSpec.doc”
Public Const constStrPreToFind As String = “Syntax*”
‘Public NGBSpecFile As Word.Document
Public NGBSpecFile
Public NGBDoc
‘ ———- log file related ———-
Public gLogFile As Object
Public gLogFullFileName As String
Function createLogFile()
‘ open the file ouput TextStream output, overwritng is necessary
Dim fso As Object
Set fso = CreateObject(“Scripting.FileSystemObject”)
‘gLogFullFileName = ThisWorkbook.Path & “” & constLogFileName
‘gLogFullFileName = Application.ActiveWorkbook.Path & “” & constLogFileName
gLogFullFileName = ActiveDocument.Path & “” & constLogFileName
Set gLogFile = fso.CreateTextFile(gLogFullFileName, True)
End Function
Function outputLogInfo(info)
gLogFile.WriteLine info
End Function
Function closeLogFile()
gLogFile.Close
Set gLogFile = Nothing
End Function
Sub justUpdateCorrelation()
Dim strToFind As String
Dim strMenuCmd As String
Dim strHeadingNumber As String
Dim strHeadingText As String
Dim pos As Integer
‘ create log file
Call createLogFile
‘strMenuCmd = “999962”
strMenuCmd = “PAPRBY”
strToFind = constStrPreToFind & strMenuCmd
ActiveDocument.Select
With Selection.Find
.MatchWildcards = True
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
‘.Wrap = wdFindContinue
.Execute FindText:=strToFind
End With
outputLogInfo strToFind & Selection.Find.Found
outputLogInfo Selection.Find.Text
Selection.Start = Selection.End
Selection.GoTo What:=wdGoToHeading, Which:=wdGoToPrevious, Count:=1 ‘go to nearest heading
Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend ‘select current line
strHeadingText = Selection.Text
strHeadingText = Replace(strHeadingText, vbCr, Space(1))
strHeadingNumber = Selection.Bookmarks(“headinglevel”).Range.ListFormat.ListString
strHeadingNumber = Trim(strHeadingNumber)
If strHeadingNumber = vbNullString Then
outputLogInfo “heading text not include bookmarks, so can not get its listString”
pos = InStr(strHeadingText, Space(1))
strHeadingNumber = Left(strHeadingText, pos – 1)
End If
outputLogInfo “[” & strMenuCmd & “]”
outputLogInfo “whole heading text: ” & strHeadingText
outputLogInfo “heading number:” & strHeadingNumber
‘ close log file
Call closeLogFile
End Sub