Home > OS >  Use VBA to extract Word heading (numbered) storage to another Word document
Use VBA to extract Word heading (numbered) storage to another Word document

Time:03-10

Will the following code is input into the Word document need to extract the title of VBA window, when open the Word document will run the following code, extract document number and title, and in the same directory of BBB. Docx document, (note: the document is larger, the running time is longer, please be patient)
Private Sub Document_Open ()
Dim t1, t2, t3, As String
Dim pcount, I As an Integer
Dim wdapp As Object
The Set wdapp=CreateObject (" word. Application ") 'create a new word document, used to store the number and title
Wdapp. Documents. The Add
Wdapp. Visible=True
Pcount=ThisDocument. Paragraphs. Total Count 'pcount for document paragraph
For I=1 To pcount
T1=ThisDocument. Paragraphs (I). The Style
If Left (t1, 2)="title" Then
T2=ThisDocument. Paragraphs (I). The Range of 't2 for title
T3=ThisDocument. Paragraphs (I) Range. ListFormat. ListString 't3 for number
Wdapp. The Documents (1). The Content. InsertAfter (t3 + t2)
End the If
Next I
Wdapp. The Documents (1). SaveAs (" BBB. Docx ") 'save as the same directory of BBB. Docx
The Set wdapp=Nothing
End Sub
  • Related