最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[tmp]get the heading number from word file

tmp_todo crifan 1971浏览 0评论

Public Const constLogFileName As String = “updateCorrelationFromDoc.txt”
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

转载请注明:在路上 » [tmp]get the heading number from word file

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
80 queries in 0.165 seconds, using 22.05MB memory