PDA

View Full Version : Moving data from Excel to Word Font Bold not working why?



chamdan
05-02-2012, 04:31 AM
Hi,
I am moving data from Excel to word and wanted that some of the text be in bold, although I am specifying Bold in my macro the results comes always as if the Bold has not been requested.
Here below is the code I have:


Const wdWindowStateMaximize As Integer = 1
Const wdNormalView As Integer = 3
Const wdAlignParagraphCenter As Integer = 1
Const wdAnimationShimmer As Integer = 6
Const wdPasteMetafilePicture As Integer = 3
Const wdInLine As Integer = 0
Const wdPageFitFullPage As Integer = 1
Const wdGoToAbsolute As Integer = 1
Const wdGoToLine As Integer = 3
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = CreateObject("Word.Application")
If FileFolderExists(sPath) Then
Set WordDoc = WordApp.Documents.Open(sPath)
With WordApp
.Visible = True
.WindowState = wdWindowStateMinimize
Set WordDoc = .ActiveDocument
WordDoc.Select
.Selection.Delete
End With
If sGroup = "000" Then
TitleHdr = "All schedule Issues in the Gantt Chart"
Else
TitleHdr = sGroupName & " Schedule Issues"
End If
Else
With WordApp
.Visible = True
.WindowState = wdWindowStateMaximize
.Documents.Add
Set WordDoc = .ActiveDocument
End With
WordDoc.Documents.SaveAs (sPath)
WordApp.Documents.Close
Set WordDoc = WordApp.Documents.Open(sPath)
End If
WordDoc.ActiveWindow.View = wdNormalView
With WordApp.Selection
.InsertAfter TitleHdr & " as at: " & Date
.InsertParagraphAfter
.MoveRight
.MoveDown , wdLine, 3
End With
With WordDoc.Paragraphs(1).Range
.ParagraphFormat.Alignment = wdAlignParagraphCenter
With .Font
.Name = "Arial"
.Size = 12
.Bold = True '<<--- This one works fine
End With
End With
With WordApp.Selection
.InsertAfter ""
.InsertParagraphAfter
.MoveDown
End With
With WordDoc.Paragraphs(2).Range
.ParagraphFormat.Alignment = wdAlignParagraphLeft
With .Font
.Name = "Arial"
.Size = 11
.Bold = False
End With
End With
If Range("B" & i).Value <> "" Then
With WordDoc.Paragraphs(2).Range
.ParagraphFormat.Alignment = wdAlignParagrapLeft
With .Font
.Name = "Arial"
.Size = 11
.Bold = True '<< ----------- This one does not ???? why???
End With
End With

With WordApp.Selection
.InsertAfter "Task Name: " & Range("B" & i).Value
.InsertParagraphAfter
.MoveDown
.MoveDown
End With

Else
If Range("C" & i).Value <> "" Then
With WordDoc.Paragraphs(2).Range
.ParagraphFormat.Alignment = wdAlignParagrapLeft
With .Font
.Name = "Arial"
.Size = 11
.Bold = True
End With
End With
With WordApp.Selection
.InsertAfter "Task Name: " & Range("C" & i).Value
.InsertParagraphAfter
.MoveDown
.MoveDown
End With


Can someone help me correct that situation? maybe I am doing something wrong. Regards,


Chuck

chamdan
05-02-2012, 04:12 PM
Got it resolved in a simplier way.
With WordDoc.Paragraphs(2).Range
.ParagraphFormat.Alignment = wdAlignParagraphLeft
With .Font
.Name = "Arial"
.Size = 11
.Bold = False
End With
End With
If Range("B" & i).Value <> "" Then
With WordDoc.Paragraphs(2).Range
.ParagraphFormat.Alignment = wdAlignParagrapLeft
With .Font
.Name = "Arial"
.Size = 11
.Bold = True
End With
End With

With WordApp.Selection
.InsertAfter "Task Name: " & Range("B" & i).Value
.InsertParagraphAfter
.Font.Bold = True
.MoveDown
.MoveDown
End With

Else
If Range("C" & i).Value <> "" Then
With WordApp.Selection
.InsertAfter "Task Name: " & Range("C" & i).Value
.InsertParagraphAfter
.Font.Bold = True
.MoveDown
.MoveDown
End With

Instead of using the Paragraph command.

Chuck
:beerchug: