Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-12-2020, 07:52 AM
lMerlo lMerlo is offline Automatic editing of a word file Windows 10 Automatic editing of a word file Office 2019
Novice
Automatic editing of a word file
 
Join Date: Feb 2020
Posts: 1
lMerlo is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 02-12-2020, 08:27 PM
macropod's Avatar
macropod macropod is offline Automatic editing of a word file Windows 7 64bit Automatic editing of a word file Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You can delete all textboxes and images by copying the entire document and pasting its content back into itself as unformatted text. This will also remove all other formatting, giving you a plain text document to work with.

Empty paragraphs can be deleted by a single Find/Replace, without a time-consuming loop through all paragraphs.

For some code to convert manually-numbered heading to proper Word headings and to apply Word's auto-numbering to those headings, see:
Convert Manual Numbering 1.0, 1.1, 1.1.1, 1.1.2 to automatic numbering - Microsoft Community
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic editing of a word file Saving file with restricted editing dcmontva Word 5 04-29-2019 05:01 PM
Make "automatic" dimensions show all the time not just when editing macleodal Visio 1 11-27-2018 08:48 PM
Sharing file without editing cb0312 Excel 0 03-22-2015 04:17 PM
Automatic editing of a word file File locked for editing by ... tep1981 Office 1 03-22-2012 03:46 PM
Help with editing a file T_L_T Word 0 08-13-2008 03:10 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft