Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-09-2018, 10:33 AM
Kalü Kalü is offline VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Windows 10 VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Office 2010 32bit
Advanced Beginner
VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters
 
Join Date: Apr 2018
Posts: 43
Kalü is on a distinguished road
Red face VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters

Hi,
I wrote a macro that finds and replace ("marks") all bold, itlaic, underlined and highlighted words in a document. It "marks" the wirds by setting a specific characters before and after the word, so Word will find the words again, when i copy and paste in a new document with pasting "Text only".

I am very sad because it is just not working 100% also i spent so many hours to get it working....
  1. It opens the dialogue which is asking if it should start the serch from the beginning instead of simply replacing all.
  2. When there are words that are bold, italic AND highlighted it is makking the following paragraph completely bold instead of only making the one word bold, itali and highlighted!


Can anybody find the error(s) in my VBA-code?

Sub aabFettKursivQuelldok()
'
' aaFettKursivQuelldok Macro
'
'
' marks all highlighted words
Selection.Find.ClearFormatting


Selection.Find.Font.Underline = wdUnderlineSingle
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(?@>)"
.Replacement.Text = "°°°°^&''''"
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' marks all underlined words
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(?@>)"
.Replacement.Text = "§§§^&%%%%"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' marks all bold words
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(?@>)"
.Replacement.Text = "####^&&&&&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' marks all italic words
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(?@>)"
.Replacement.Text = "~~^&+++"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

End Sub


Sub aabFettKursivZieldok()
'
' aaFettKursivZieldok Macro
'
' replaces all underlined-marked words
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Underline = wdUnderlineSingle
With Selection.Find
.Text = "°°°°(?@>)''''"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' replaces all highlighted-marked words
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = True
With Selection.Find
.Text = "§§§(?@>)%%%%"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' replaces all bold-marked words
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Bold = True
With Selection.Find
.Text = "####(?@>)&&&&"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' replaces all italic-marked words
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = "~~(?@>)+++"
.Replacement.Text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

' deletes all marks:
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "°°°°"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "''''"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "§§§"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "%%%%"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "####"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "&&&&"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "~~"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = "+++"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

End Sub
Reply With Quote
  #2  
Old 04-09-2018, 03:11 PM
macropod's Avatar
macropod macropod is offline VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Windows 7 64bit VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters 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

Quote:
Originally Posted by Kalü View Post
It opens the dialogue which is asking if it should start the serch from the beginning instead of simply replacing all.
That's because you've used:
.Wrap = wdFindAsk
in one place instead of:
.Wrap = wdFindContinue
Quote:
Originally Posted by Kalü View Post
When there are words that are bold, italic AND highlighted it is makking the following paragraph completely bold instead of only making the one word bold, itali and highlighted!
There is nothing about your code that would cause it to do that.

That said, your code's efficiency could be greatly improved. For your first macro, try:
Code:
Sub aabFettKursivQuelldok()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = True
  .Forward = True
  .MatchWildcards = True
  .Wrap = wdFindContinue
  .Font.Underline = True
  .Text = "(?@>)"
  .Replacement.Text = "°°°°^&''''"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Highlight = True
  .Replacement.Text = "§§§^&%%%%"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Font.Bold = True
  .Replacement.Text = "####^&&&&&"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Font.Italic = True
  .Replacement.Text = "~~^&+++"
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-09-2018, 03:39 PM
macropod's Avatar
macropod macropod is offline VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Windows 7 64bit VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters 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

Cross-posted at: http://www.vbaexpress.com/forum/show...find-the-Error
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 04-10-2018, 04:33 AM
Kalü Kalü is offline VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Windows 10 VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Office 2010 32bit
Advanced Beginner
VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters
 
Join Date: Apr 2018
Posts: 43
Kalü is on a distinguished road
Default

Wow thank you very much, that looks great!!!

The second macro cannot be done in your style because the find what text differs for bold, italic, underlined and highlighted - right?

Quote:
There is nothing about your code that would cause it to do that.
I thought so too, but please hava alook at the following picture (im sorry it is not working to directly post):
https://imgur.com/a/ovLAC

I have no idea why it is doing this

And I have an additional question: Is it possible to turn off hyphenation in the document by using a vba-command and integrate this command in the first macro?


Thank you very very much for your help and sorr im such a nooooob
Reply With Quote
  #5  
Old 04-10-2018, 04:41 AM
Kalü Kalü is offline VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Windows 10 VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Office 2010 32bit
Advanced Beginner
VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters
 
Join Date: Apr 2018
Posts: 43
Kalü is on a distinguished road
Default

And sorry for "crossposting" but I didnt know that these two forums belong together (
Reply With Quote
  #6  
Old 04-10-2018, 09:46 PM
macropod's Avatar
macropod macropod is offline VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Windows 7 64bit VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters 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

Quote:
Originally Posted by Kalü View Post
The second macro cannot be done in your style because the find what text differs for bold, italic, underlined and highlighted - right?
Not at all. Exactly the same approach can be taken.
Code:
Sub aabFettKursivZieldok()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = True
  .Forward = True
  .MatchWildcards = True
  .Wrap = wdFindContinue
  .Replacement.Text = "\1"
  .Text = "°°°°(?@>)''''"
  .Replacement.Font.Underline = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "§§§(?@>)%%%%"
  .Replacement.Highlight = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "####(?@>)&&&&"
  .Replacement.Font.Bold = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "~~(?@>)+++"
  .Replacement.Font.Italic = True
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
Quote:
Originally Posted by Kalü View Post
I thought so too, but please hava alook at the following picture
...
I have no idea why it is doing this
I don't see anything in your post that evidences either your first macro or mine has been run in it (there's none of your prefix/suffix strings, for example).
Quote:
Originally Posted by Kalü View Post
And I have an additional question: Is it possible to turn off hyphenation in the document by using a vba-command and integrate this command in the first macro?
All you need for that is:
ActiveDocument.AutoHyphenation = False
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-11-2018, 04:45 AM
Kalü Kalü is offline VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Windows 10 VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Office 2010 32bit
Advanced Beginner
VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters
 
Join Date: Apr 2018
Posts: 43
Kalü is on a distinguished road
Default

First of all: Thank you really very much you are helping me a lot!! And wow.. Wish I had more know-how.. Is there any tutorial you can advice me for getting more into vba-macros?

Quote:
I don't see anything in your post that evidences either your first macro or mine has been run in it (there's none of your prefix/suffix strings, for example).
This is because the second macro is deleting all "marks"/strings so tthat the text should look like before... But it doesnt get the highlight and instead continues to format the words bold, also they should be normal.

Strange thing is : it is actually working, just the bold, italic AND highlighted words seem to cause this error. Maybe my "marks" are too long or bad-choosen so that tthey come in conflict when they are next to each other? But i tried it with othe marks and it wasnt working neither... I just cant get whats te problem..
Reply With Quote
  #8  
Old 04-11-2018, 03:00 PM
macropod's Avatar
macropod macropod is offline VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Windows 7 64bit VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters 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

I am unable to replicate the behaviour you describe. Perhaps you could attach the actual document exhibiting the behaviour to a post (delete anything sensitive). You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.

As for the codes you're using, I'd have been inclined to used something closer to standard HTML:
Code:
Sub aabFettKursivQuelldok()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = True
  .Forward = True
  .MatchWildcards = True
  .Wrap = wdFindContinue
  .Font.Underline = True
  .Text = ""
  .Replacement.Text = "<u>^&</u>"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Highlight = True
  .Replacement.Text = "<h>^&</h>"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Font.Bold = True
  .Replacement.Text = "<b>^&</b>"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Font.Italic = True
  .Replacement.Text = "<i>^&</i>"
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
Code:
Sub aabFettKursivZieldok()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = True
  .Forward = True
  .MatchWildcards = True
  .Wrap = wdFindContinue
  .Replacement.Text = "\1"
  .Text = "\<u\>(*)\</u\>"
  .Replacement.Font.Underline = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "\<h\>(*)\</h\>"
  .Replacement.Highlight = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "\<b\>(*)\</b\>"
  .Replacement.Font.Bold = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "\<i\>(*)\</i\>"
  .Replacement.Font.Italic = True
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
Note that the first macro above also doesn't specify the 'find' text. That way, multiple consecutive words in a given format need only have a single set of each kind of tagging. As coded, that macro will also insert the </i>, etc. after any formatted paragraph mark. To exclude the paragraph marks, change:
.Text = ""
to:
.Text = "[!^13]{1,}"
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 04-12-2018, 06:42 AM
Kalü Kalü is offline VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Windows 10 VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Office 2010 32bit
Advanced Beginner
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters
 
Join Date: Apr 2018
Posts: 43
Kalü is on a distinguished road
Default

Dear Paul,

I am in love with your improved macros! They are working great and a lot faster than mine.

Even the problem described above is -nearly- solved by it!

I attached a Word2010 document as example. It works all fine, only after "1. Heading xy" the number 1.1 in the following paragraph becomes highlighted (after pasting in a new document and running the second macro).

You can also see it at the tags, that end after 1.1 and not after Heading xy as they should. Is this maybe because of the automatic numbering?
Attached Files
File Type: docx VBA EXample.docx (53.1 KB, 15 views)
File Type: docx VBA EXample_first macro ran through.docx (53.8 KB, 13 views)

Last edited by Kalü; 04-12-2018 at 10:31 AM.
Reply With Quote
  #10  
Old 04-12-2018, 02:04 PM
macropod's Avatar
macropod macropod is offline VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Windows 7 64bit VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters 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

Quote:
Originally Posted by Kalü View Post
I attached a Word2010 document as example. It works all fine, only after "1. Heading xy" the number 1.1 in the following paragraph becomes highlighted (after pasting in a new document and running the second macro).

You can also see it at the tags, that end after 1.1 and not after Heading xy as they should. Is this maybe because of the automatic numbering?
That's because the bold/italic formatting is applied to the paragraph break in your document and, to faithfully replicate that, the formatting code has to follow the paragraph break - just as it does with any other text. It has no effect on the final result for the following paragraph, though - after running the second macro, the original formatting is restored. In any event, the comments at the end of the post show how to prevent paragraphs breaks being tagged.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 04-13-2018, 07:09 AM
Kalü Kalü is offline VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Windows 10 VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Office 2010 32bit
Advanced Beginner
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters
 
Join Date: Apr 2018
Posts: 43
Kalü is on a distinguished road
Default

Sadly it is not restoring the original formatting. The automatic number (1.1) in the following paragraph will be highlighted also it should not

But I guess there is no solution for it, or is there any?

Where is your Donate-Button? I would like to give you some tip for your great help!!
Reply With Quote
  #12  
Old 04-13-2018, 03:20 PM
macropod's Avatar
macropod macropod is offline VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Windows 7 64bit VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters 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

I am unable to replicate the behaviour you say is occurring when I run the macros against your 'VBA Example' attachment. And just to make sure, I added:
ActiveDocument.Range.Font.Reset
to the end of the first macro to strip out all character-level formatting (Paragraph Style formatting remains formatted as such).
Quote:
Originally Posted by Kalü View Post
Where is your Donate-Button? I would like to give you some tip for your great help!!
We don't have one; all help here is gratis.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 04-16-2018, 04:54 AM
Kalü Kalü is offline VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Windows 10 VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Office 2010 32bit
Advanced Beginner
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters
 
Join Date: Apr 2018
Posts: 43
Kalü is on a distinguished road
Default

Well thats weird because I still have the problem (please see in the attached document: 1.1 is highlighted).

Could it be that I added "ActiveDocument.Range.Font.Reset" at the wrong place in the macro? My first macro now looks like this:
Code:
Sub aaaaaQuelldok()
' hyphenation off
ActiveDocument.AutoHyphenation = False
'tag all formatted words
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = True
  .Forward = True
  .MatchWildcards = True
  .Wrap = wdFindContinue
  .Font.Underline = True
  .Text = ""
  .Replacement.Text = "<u>^&</u>"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Highlight = True
  .Replacement.Text = "<h>^&</h>"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Font.Bold = True
  .Replacement.Text = "<b>^&</b>"
  .Execute Replace:=wdReplaceAll
  .ClearFormatting
  .Font.Italic = True
  .Replacement.Text = "<i>^&</i>"
  .Execute Replace:=wdReplaceAll
End With
ActiveDocument.Range.Font.Reset
Application.ScreenUpdating = True
End Sub
and just to complete the second macro looks like this:
Code:
Sub aaaaaZieldok()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = True
  .Forward = True
  .MatchWildcards = True
  .Wrap = wdFindContinue
  .Replacement.Text = "\1"
  .Text = "\<u\>(*)\</u\>"
  .Replacement.Font.Underline = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "\<h\>(*)\</h\>"
  .Replacement.Highlight = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "\<b\>(*)\</b\>"
  .Replacement.Font.Bold = True
  .Execute Replace:=wdReplaceAll
  .Replacement.ClearFormatting
  .Text = "\<i\>(*)\</i\>"
  .Replacement.Font.Italic = True
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
Attached Files
File Type: docx After running second Macro.docx (55.7 KB, 10 views)
Reply With Quote
  #14  
Old 04-16-2018, 05:20 AM
macropod's Avatar
macropod macropod is offline VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Windows 7 64bit VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters 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

Your latest attachment is not the same 'VBA Example' document you attached in post #9 after running both macros; it is an entirely different document, with different margins, different justification rules vis-ŕ-vis WordPerfect and no automatic numbering. Even the 'Title' paragraph is left-aligned instead of being centred. If ever the latest attachment was based on the 'VBA Example' document you attached in post #9, you've done far more to it than just running those two macros.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 04-16-2018, 05:21 AM
Kalü Kalü is offline VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Windows 10 VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Office 2010 32bit
Advanced Beginner
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters
 
Join Date: Apr 2018
Posts: 43
Kalü is on a distinguished road
Default

Ok I just formatted a document by usig the new imrpoved macor and found out it doesnt work at all

Sad thing is that it is sensitive data and i cannot post here. But i can copy some examples, after running the frst makro, copy&paste in a new document and running the second macro i got a lot of passages that looks like this:
  • 8. <B>PRZEJĘCIE
    8.1.1 </B>text
  • PLACE__________ DATE
    <B>NAME</B>
  • <B>TEXT:
    (A) </B>xyz Agent
  • and then i have got over 5 pages which are completely bold AND having the <b> <\b> tag in it a few times on every page
It looks like the Macor is not working with capitalized letters. and it looks like there is another error because of the 5 pages completely bold... I have no idea whats wrong with the macro ;((

Interesting thing: when i run my old, long macros it works a little bit better and i dont get 5 pages completely bold.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Macro to find and replace headings in bold and underline redzan Word VBA 4 02-13-2016 12:24 PM
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Find, select, and replace part of text with bold paik1002 Word VBA 4 12-07-2015 11:24 PM
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Find and Replace some characters with Bullets kjxavier Word 1 01-02-2015 12:15 AM
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters Find/Replace Wildcard Needed-Bold & Highlight rsrasc Word VBA 3 11-11-2014 03:55 PM
VBA Find&amp;Replace all bold, itlaic, underlined and highlighted words/characters find and replace in bold redzan Word VBA 1 07-27-2014 03:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:31 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