I am Dynamically generating a proposal(report ) in MS Word. By default the Paragraph Alignment is "Left". For the First 6 Paragraphs I set the Alignment to "Center", and then when attempting to switch back to "Left" aligned for remaining paragraphs, the text within the Word document remained Centered.
I'm using: VS2008 w/ .NET Framework 3.5, Microsoft.Offic e.Interop.Word Version 12.0.0.0, and I'm creating the document as a 97-2003 document though in my test environment the document is opening in Word 2007.
When stepping thru the code in Debug, both the "oPara(x).Align ment" & "oPara(x).Forma t.Microsoft.Off ice.Interop.Wor d.ParagraphForm atClass.Alignme nt" are being assigned the correct values: wdAlignParagrap hLeft{0}
I'm using: VS2008 w/ .NET Framework 3.5, Microsoft.Offic e.Interop.Word Version 12.0.0.0, and I'm creating the document as a 97-2003 document though in my test environment the document is opening in Word 2007.
Code:
'Create Word Application
g_oWord = CreateObject("Word.Application")
'Create new word document
g_oDoc = g_oWord.Documents.Add() '"C:\GraphicFile.jpg"
'Dim oHeader As Word.HeaderFooter
'Dim oSection(3) As Word.Section
'Make Word Document Invisible
g_oWord.Visible = False
'Insert Each Field after the previous
Dim oPara(8) As Word.Paragraph
Dim x As Integer = 1
'oRange(0) = oWord.ActiveDocument
oPara(0) = g_oDoc.Content.Paragraphs.Add
oPara(0).Range.Font.Bold = True
oPara(0).Range.Font.Size = 22
oPara(0).Range.Text = vbNewLine
oPara(0).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara(1) = g_oDoc.Content.Paragraphs.Add
oPara(1).Range.Font.Bold = True
oPara(1).Range.Font.Size = 22
oPara(1).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara(1).Range.Text = "List Each Product Here" & vbNewLine & "Proposal" & vbNewLine & vbNewLine
oPara(2) = g_oDoc.Content.Paragraphs.Add
oPara(2).Range.Font.Bold = True
oPara(2).Range.Font.Size = 20
oPara(2).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara(2).Range.Text = "Presented to" & vbNewLine & vbNewLine
oPara(3) = g_oDoc.Content.Paragraphs.Add
oPara(3).Range.Font.Bold = True
oPara(3).Range.Font.Size = 18
oPara(3).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara(3).Range.Text = "Customer Name" & vbNewLine & vbNewLine
oPara(4) = g_oDoc.Content.Paragraphs.Add
oPara(4).Range.Font.Bold = True
oPara(4).Range.Font.Size = 18
oPara(4).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara(4).Range.Text = "by" & vbNewLine & "Agency Name" & vbNewLine & "Proposal Date" & vbNewLine & vbNewLine & vbNewLine & vbNewLine
oPara(5) = g_oDoc.Content.Paragraphs.Add
oPara(5).Range.Font.Bold = False
oPara(5).Range.Font.Size = 10
oPara(5).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
oPara(5).Range.InlineShapes.AddPicture(logo)
oPara(6) = g_oDoc.Content.Paragraphs.Add
oPara(6).Range.Font.Italic = True
oPara(6).Range.Font.Size = 10
oPara(6).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
oPara(6).Range.Text = "" & vbNewLine & "Company Name Here"
oPara(7) = g_oDoc.Content.Paragraphs.Add
oPara(7).Range.Font.Bold = False
oPara(7).Range.Font.Size = 12
oPara(7).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
oPara(7).Range.Text = ""
Comment