![]() |
|
#1
|
|||
|
|||
|
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
I think it needs to happen around the area marked "Here something magic" etc. Can any kind soul point me in the right direction? |
|
#2
|
|||
|
|||
|
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 |
|
| Tags |
| bold, font, underline |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to I make text Bold in a User Form -Visual Basic
|
gurp99 | Word VBA | 11 | 03-12-2012 04:05 PM |
Animate text to bold then animate text to regular?
|
seanspotatobusiness | PowerPoint | 2 | 01-13-2011 12:08 PM |
exporting bold text from excel to word?
|
stella@happisburgh.net | Excel | 3 | 12-05-2010 08:03 AM |
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 |