Bold, Italic Text
Bold, Italic Text
Bold, Italic Text
Bold, Italic Text
Bold, Italic Text
Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text
Bold, Italic Text Bold, Italic Text
Bold, Italic Text
Go Back  Xtreme Visual Basic Talk > > > > Bold, Italic Text


Reply
 
Thread Tools Display Modes
  #1  
Old 10-15-2014, 08:24 AM
star123 star123 is offline
Newcomer
 
Join Date: Mar 2012
Posts: 15
Default Bold, Italic Text


Hi Guys,
I got this macro from net. It is used to insert tags in MS Word.
Its works fine. It’s insert tags for bold, italic and underlined text.
What’s the problem is, when a bold text, or Italic text or underlined text flows to the next para it insert the tag (red text) as follows.

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over <b>the lazy dog.

The quick brown fox jumps over the lazy dog.
</b>

But What I need is, If the bold text flow to the next para. It should be as follows:

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over <b>the lazy dog.</b>

<b>The quick brown fox jumps over the lazy dog.
</b>

Is there a way to do this.

Thanks in advance

Last edited by star123; 10-15-2014 at 08:31 AM.
Reply With Quote
  #2  
Old 10-18-2014, 05:56 AM
star123 star123 is offline
Newcomer
 
Join Date: Mar 2012
Posts: 15
Default

OOps.... forget to insert the code. Here it is....


Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Text = ""
.Font.Bold = True
.Replacement.Text = "<b>^&</b>"
.Replacement.Font.Bold = False
.execute replace:=wdReplaceAll
.ClearFormatting
.Font.Italic = True
.Replacement.Text = "<i>^&</i>"
.Replacement.Font.Italic = False
.execute replace:=wdReplaceAll
.ClearFormatting
.Font.Underline = True
.Replacement.Text = "<u>^&</u>"
.Replacement.Font.Underline = False
.execute replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub

Last edited by star123; 10-18-2014 at 06:09 AM.
Reply With Quote
  #3  
Old 06-16-2017, 10:52 AM
Daigon Ali Daigon Ali is offline
Regular
 
Join Date: Aug 2014
Location: London
Posts: 59
Default

I'd do it a paragraph at a time.

Code:
Sub Demo()
Application.ScreenUpdating = False
For p = 1 To ActiveDocument.Paragraphs.Count
    With ActiveDocument.Paragraphs(p).Range
        With .Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Forward = True
            .Wrap = wdFindStop
            .Format = True
            .Text = ""
            .Font.Bold = True
            .Replacement.Text = "<b>^&</b>"
            .Replacement.Font.Bold = False
            .Execute Replace:=wdReplaceAll
            .ClearFormatting
            .Font.Italic = True
            .Replacement.Text = "<i>^&</i>"
            .Replacement.Font.Italic = False
            .Execute Replace:=wdReplaceAll
            .ClearFormatting
            .Font.Underline = True
            .Replacement.Text = "<u>^&</u>"
            .Replacement.Font.Underline = False
            .Execute Replace:=wdReplaceAll
        End With
    End With
Next
Application.ScreenUpdating = True
End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Bold, Italic Text
Bold, Italic Text
Bold, Italic Text Bold, Italic Text
Bold, Italic Text
Bold, Italic Text
Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text Bold, Italic Text
Bold, Italic Text
Bold, Italic Text
 
Bold, Italic Text
Bold, Italic Text
 
-->