最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

[tmp]get the heading number from word file

tmp_todo crifan 685浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
57 queries in 0.218 seconds, using 18.78MB memory