make tekst Bold with a macro

G

Grimmie

Hello,

I have a Word document after merge I have the following text:

--------------------------------------------------------------------------------


<mergefield title> fdsfasdfsadfdsafds </mergefield title>

<mergefield body>
<b>something 1</b>

dasdasdwadasdafdasfasfsdf
dsfdsfdsfsdfsdfsdfsdfds
fsdfsdfdsfdsfdsfdsfds

<b>something 2</b>

dasdasdwadasdafdasfasfsdf
dsfdsfdsfsdfsdfsdfsdfds
fsdfsdfdsfdsfdsfdsfds </mergefield body>
 
H

Helmut Weber

Hi,
like this:

Sub Test655()
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
ResetSearch
With rDcm.Find
.Text = "(\<b\>)(*)(\</b\>)"
.Replacement.Text = "\2"
.Replacement.Font.Bold = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
ResetSearch
End Sub

Public Sub ResetSearch()
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub

See:
http://word.mvps.org/faqs/General/UsingWildcards.htm


Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
G

Grimmie

Tnx, that works...

Is there also a way to do all HTML tags ? <b><u><i><h1><h2> etc.
h1 = wdStyleHeading1
h2 = wdStyleHeading2
etc.

But instead of the search and replace function can Word convert all the HTML
tags with a (builtin ?) function ? I probably still have to use a Macro, but
that is no problem.
 
H

Helmut Weber

Hi Grimmie,
....
answered one question and there comes the next one.
....
Try asking in microsoft.public.word.docmanagement.
The VBA group is kind of a group for do-it-yourselfers.

I don't know much about all that HTML-stuff.

Cheers.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
G

Grimmie

I thought this newsgroup was for asking VBA-related questions ?
And I am a programmer (SQL/ASP/C/XML/XSL/XSD/...), just not in VBA.

But tnx anyway.
 
L

Lesley Regan

Hi, Grimmie,

1. Word doc Save As Web Page
2. View, Html source
3. Paste in the text with HTML tags

See if that helps....Web pages have two faces -- a formatted front with no
tags, and a back with the HTML and text, as I'm sure you know.

I've tried different ways of translating the HTML tags into formatting on
the face of a Word document before and it's really an exercise in futility.

Regards,

Lesley
 
H

Helmut Weber

Hi Grimmie,
using a built in function has nothing to do with programming.

..Text = "(\<b\>)(*)(\</b\>)" ' bold
..Text = "(\<u\>)(*)(\</u\>)" ' underline
..Text = "(\<i\>)(*)(\</i\>)" ' italic

For heading:

With rDcm.Find
.Text = "(\<h1\>)(*)(\</h1\>)"
.Replacement.Text = "\2"
.Replacement.Style = "Überschrift 1" ' German Version
' Your stylename for heading 1
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With

Otherwise, put the text in notepad.
Save it as "xyz.htm".

Open it with Word.
Confirm question for conversion.

HTH

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top