Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2012, 10:36 AM
Sorcerer13 Sorcerer13 is offline Set paragraph text to bold. Windows Vista Set paragraph text to bold. Office 2010 32bit
Novice
Set paragraph text to bold.
 
Join Date: Sep 2012
Location: God's Own County
Posts: 16
Sorcerer13 is on a distinguished road
Default Set paragraph text to bold.

Hi!
Sorry if this is an "amateur" question: i've used VBA in Excel fairly extensively, but not much in Word.
Im using MSOffice 2010.
I have a template document with (working) code in it, which asks the User for various details. These details are processed and stored in a dynamic array, until the User indicates that the "data gathering" has completed.
At this point I want to write the array to the end of the document, with each element of the array being a "sentence". This bit is working.
Extracts from the code are shown below

Code:
 
Dim intMax                  As Integer
Dim intPtr                  As Integer
Dim strDate                 As String
Dim strCategory             As String
Dim strHdr                  As String
Dim strOldCategory          As String
Dim strText                 As String
 
 
  strOldCategory = ""
 
 
  With ActiveDocument.Content
    .InsertAfter vbCrLf
    intMax = UBound(gvarTexts)
'*
'** Add texts, with formatting if appropriate.
'*
    For intPtr = 0 To intMax
      strCategory = Left(gvarTexts(intPtr), 20)
      strDate = Mid(gvarTexts(intPtr), 22, 10)
      strText = Mid(gvarTexts(intPtr), 33)
      If strCategory <> strOldCategory Then
        strOldCategory = strCategory
        strHdr = strCategory & ":" & strDate
        .InsertAfter vbCrLf & strHdr & vbCrLf
'*
'** Here something magic needs to happen to change strHdr
'** which has just been written to be Bold and Underlined!
'*
      End If
      .InsertAfter strText & vbCrLf
    Next intPtr
In essence, the first part of each array string is a "Category". When the Category changes I want to write the new Category in Bold and Underlined, then continue writing the texts which match that Category in the normal way (i.e. not bold or underlined).


I think it needs to happen around the area marked "Here something magic" etc.
Can any kind soul point me in the right direction?
Reply With Quote
  #2  
Old 09-04-2012, 11:08 AM
gmaxey gmaxey is online now Set paragraph text to bold. Windows XP Set paragraph text to bold. Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Something like this and I didn't see the underline bit until after I had composed the code. You should get the jist:

Sub ScratchMacro()
'A quick macro scratch pad created by Greg Maxey
Dim i As Long
Dim oRng As Word.Range
Dim arrDemo(2, 2) As String
arrDemo(0, 0) = "Category A"
arrDemo(0, 1) = "Item 1"
arrDemo(0, 2) = "Size A"
arrDemo(1, 0) = "Category B"
arrDemo(1, 1) = "Item 1"
arrDemo(1, 2) = "Size B"
arrDemo(2, 0) = "Category C"
arrDemo(2, 1) = "Item 1"
arrDemo(2, 2) = "Size C"
For i = 0 To UBound(arrDemo)
ActiveDocument.Range.InsertAfter vbCr
Set oRng = ActiveDocument.Paragraphs.Last.Range
oRng.MoveEnd wdCharacter, -1
oRng.Text = arrDemo(i, 0)
oRng.Font.Bold = True
oRng.Collapse wdCollapseEnd
oRng.Text = " " & arrDemo(i, 1)
oRng.Font.Bold = False
oRng.Collapse wdCollapseEnd
oRng.Text = " " & arrDemo(i, 2)
Next i
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
bold, font, underline

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set paragraph text to bold. How to I make text Bold in a User Form -Visual Basic gurp99 Word VBA 11 03-12-2012 04:05 PM
Set paragraph text to bold. Animate text to bold then animate text to regular? seanspotatobusiness PowerPoint 2 01-13-2011 12:08 PM
Set paragraph text to bold. exporting bold text from excel to word? stella@happisburgh.net Excel 3 12-05-2010 08:03 AM
Set paragraph text to bold. Can't print bold or italic text cornettd PowerPoint 1 05-10-2010 10:07 AM
Problem with Bold text in the headers gail Word 0 04-13-2010 02:15 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:32 PM.


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