Automatic editing of a word file
Hi, this mounth I'll Have to edit some text and I Would like not to do this manually so i decided to write a vba code to do the job but i had some trobles. Probably the situation has been complicated by the fact that the word file i have has been generated as the imported file of a word
What i would like to have is :
Delete all imagaes and text boxes
Change the style of the indexes that are in front of line whose style is list paragraph beacuse i don't want them to be changed if a change the title level
Automatclaly assign the stile after having checked the index in front of a line
Delete all empty paragraph
i think an automatic index has been used and i find it difficult to have access to some part of the file
Dim shp As Shape
For Each shp In ActiveDocument.Shapes
shp.Delete
Next shp
some figure will has been imported as a lot of text boxes. so i would like all the figure and text boxes to be remouved. But the code doesn't do this action always
Dim numPara As Long
numPara = ActiveDocument.Paragraphs.Count
Dim aRange As Range
For i = numPara To 1 Step -1
Set aRange = ActiveDocument.Paragraphs(1).Range
If Len(aRange) <= 1 Then oPara.Delete
End If
This code wold have to remouve the paragraph if i have something like
¶
¶
But i think there is a problem with the use of len applied to a paragraph
Dim numPara As Integer
numPara = ActiveDocument.Paragraphs.Count
For i =numPara to 1 Step -1
If (ActiveDocument.Paragraphs(i).Format.Style Like "List Paragraph") Then
ActiveDocument.Paragraphs(i).Range.ListFormat.Conv ertNumbersToText
End If
Next i
I wold like to obtain at the end something like
1 Heading 1
1.1 Heading 2
1.1.1 Heading 3
1.1.1.1 heading 4
1.1.1.1.1 Normal, or body text
For me it is important that even if i modefy the tytle structure, the number like 1.1.1.1.1 won't change
Actually this the only part that functions
Dim numPara As Integer
Dim final As Integer
Dim str As String
Dim cond1 As Boolean
Dim cond2 As Boolean
Dim head1 As Style, head2 As Style, head3 As Style, head4 As Style
numPara = ActiveDocument.Paragraphs.Count
final = numPara - 500
For i = numPara To final Step -1
str = ActiveDocument.Paragraphs(i).Range.ListFormat.List String
Set head1 = ActiveDocument.Styles("Heading 1")
Set head2 = ActiveDocument.Styles("Heading 2")
Set head3 = ActiveDocument.Styles("Heading 3")
Set head4 = ActiveDocument.Styles("Heading 4")
cond1 = ActiveDocument.Paragraphs(i).Format.Style Like "Normal"
cond2 = ActiveDocument.Paragraphs(i).Format.Style Like "Body Text"
cond3 = Not cond1
cond4 = Not cond2
If cond1 Or cond2 Then
Debug.Print i
If str Like "#[.]#" Then ActiveDocument.Paragraphs(i).Style = wdStyleHeading2
If str Like "#[.]#[.]#" Then ActiveDocument.Paragraphs(i).Style = wdStyleHeading3
If str Like "#[.]#[.]#[.]#" Then ActiveDocument.Paragraphs(i).Style = wdStyleHeading4
End If
Next i
When the pdf is impoted it may happen that the heading level are matched to the wrong Heading so i want to check the type of index and change the heading.
Do you have and idea of what to do if i find a document where the title are not even heading ?
Thanks for your help
|