Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

make tekst Bold with a macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Grimmie - 29 Dec 2004 10:50 GMT
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>

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

The headers (<mergefield title>) come from a different mergefield, so I can format this header easily. But the body contains <b>something 1</b>, now I want this to be really bold in Word instead of these <b> tags.
Helmut Weber - 29 Dec 2004 11:23 GMT
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/
Grimmie - 29 Dec 2004 11:58 GMT
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.

> Hi,
> like this:
[quoted text clipped - 39 lines]
> Word XP, Win 98
> http://word.mvps.org/
Helmut Weber - 29 Dec 2004 12:13 GMT
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/

>Tnx, that works...
>
[quoted text clipped - 50 lines]
>> Word XP, Win 98
>> http://word.mvps.org/
Grimmie - 29 Dec 2004 13:51 GMT
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.
Lesley Regan - 29 Dec 2004 16:31 GMT
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

> 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.
Helmut Weber - 29 Dec 2004 20:23 GMT
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/

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.