Hi,
I am working on a macro application where i take data from excel and generate a report with images and tables and a lot of text.
And am facing issues already. I have included the word object reference to the vba project, and have used the following code in class CoverGenerator which implements Generator
Code:
Public Sub Generator_printInDoc(ByRef doc As document)
Dim para As paragraph
Set para = doc.Paragraphs.Add
para.Range.Text = "Heading"
para.Format.Alignment = wdAlignParagraphRight
On Error Resume Next
para.Range.Font.Size = 18
If Err.Number <> 0 Then MsgBox Err.Description
'I get "Method Size of Object _Font failed" as error. why is it considering it as a method? is it a leter in font class? if so why is it failing?
para.Range.Font.name = "Cambria"
For i = 0 To 8
Set para = doc.Paragraphs.Add
para.Space2
Next
Set para = doc.Paragraphs.Add
With para
.Range.Text = "Title Text Comes here"
.Alignment = wdAlignParagraphCenter
.Format.Space15
.Range.Font.Size = 14
.Range.Font.Bold = True
End With
End Sub
Except for the font size, everything else works, even the font name!!
The same code inside the word file doesn't throw any error. Can someone tell where I am going wrong? or if its a problem caused because of manipulating word objects in excel macro?
I am using: office 2011
OS: snow leopard
Please help!
Thanks