Word object in vb.net

x_cure

New member
Joined
Jul 15, 2005
Messages
1
Programming Experience
Beginner
hello!

i want to load an existing word file into a vb project, and then
to save each page in defferent file. The file i want to load, is an edited file!
i dont want to make changes in it. i just want to "take" each existing page inside that document, and to save them in different files.

thanks a lot!
 
Last edited:
Too many ideas never enough $$$/time :D JK :)

Ok, this is a short example that loads word template and and pass some value/s to the document and finally save .doc file.

I will not type entire project but if you need a total demo and this is not enough to get sense ... i could attach the project in next post.

PHP:
 Dim oWord As Word.Application 
 
Dim oDoc As Word.Document
 
Dim oTable As Word.Table 'this is if you want to draw a table/s
 
 
Dim oPar1 As Word.Paragraph
Dim oRng As Word.Range
 
Dim oShape As Word.InlineShapes 'if you want to add a picture 
 
Dim lineNew As Word.Shape
 
 
'Start Word and open the document template.
 
oWord = CreateObject("Word.Application")
 
Word.Visible = True 'doc will be open during you draw the text or whatever else
oDoc = oWord.Documents.Add(Application.StartupPath & "\Diploma.dot", True)
 
 
'Insert a paragraph at the start of the document with line.
 
'** \endofdoc is a predefined bookmark.
 
oPar1 = oDoc.Content.Paragraphs.Add(oDoc.Bookmarks.Item("\endofdoc").Range)
 
oPar1.Range.Text = "This is the Title" 'note that you can pass any value here like textbox.text
 
oPar1.Range.Font.Bold = True
 
oPar1.Range.Font.Size = 16
 
oPar1.Range.Font.Spacing = 6
 
lineNew = oDoc.Shapes.AddLine(70, 100, 530, 100) 'Add new line to document
 
'Format line
 
With lineNew.Line 'Format line
 
.BeginArrowheadStyle = Core.MsoArrowheadStyle.msoArrowheadNone
 
.EndArrowheadStyle = Core.MsoArrowheadStyle.msoArrowheadStealth
 
.ForeColor.RGB = RGB(Red:=128, Green:=0, Blue:=0)
 
EndWith
 
oPar1.Format.SpaceBefore = 34
 
oPar1.Format.SpaceAfter = 10
 
oPar1.Range.InsertParagraphAfter()
 
{...} 'more code 
 
 
'and finally save the file
oDoc.SaveAs("C:\myFile.doc")
 
oWord.Documents.Close(Word.WdSaveOptions.wdSaveChanges)
 
oDoc = Nothing
 
oWord.Quit()
 
oWord = Nothing


Cheers ;)
 
Back
Top