Problem writing text in to a Word document

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have created the document in code but now I want to add text to a specific place in the document. I dont want the standard alignment. I want to put the text let say 40 spaces right or 30 spaces right. This is the code I
have for creating the document and adding the text.


<pre class="prettyprint lang-vb Dim oApp As New Microsoft.Office.Interop.Word.Application
Dim oDoc As New Microsoft.Office.Interop.Word.Document
Dim oPara1 As Word.Paragraph

oApp = CreateObject("Word.Application")
oDoc = oApp.Documents.Add
Dim strDocName As String

Insert a paragraph at the beginning of the document.
oPara1 = oDoc.Content.Paragraphs.Add
oPara1.Range.Text = "This is a test for Word"
oPara1.Range.Font.Bold = True
oPara1.Format.SpaceBefore = 25 100 pt spacing after paragraph.
oPara1.Range.Font.Size = 14
oPara1.Range.Font.Name = "Times New Roman"

oPara1.Range.Italic = True
oPara1.Range.Font.Color = RGB(0, 0, 128)
oPara1.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight

oPara1.Range.InsertParagraphAfter()

To ser the margins
oDoc.PageSetup.LeftMargin = 0
oDoc.PageSetup.RightMargin = 0
oDoc.PageSetup.TopMargin = 0


Save the document
oApp.Documents.Save()
Show Word if you wish
oApp.Visible = True
oApp.Activate()[/code]
<br/>


View the full article
 
Back
Top