L
lou_1
hey all,
ok, what i am trying to do is, by using the Word Automation Porgramming
Objects, to dynamically create a Word document using VB.NET. Here is my code
so far:
Dim objWord As Word.Application
Dim objDoc0 As Word.Document, objDoc1 As Word.Document
Dim objTable As Word.Table
Dim objShape As Word.InlineShape
'Start Word and open the document template.
objWord = CreateObject("Word.Application")
objWord.Visible = True
objDoc0 = objWord.Documents.Add
objWord.MailingLabel.DefaultPrintBarCode = False
objDoc1 = objWord.MailingLabel.CreateNewDocument(Name:="5162")
objDoc1.Tables.Item(1).Range.ParagraphFormat.SpaceAfter = 0
objDoc1.Tables.Item(1).AllowPageBreaks = True
For rowCounter = 1 To objDoc1.Tables.Item(1).Rows.Count
For colCounter = 1 To objDoc1.Tables.Item(1).Columns.Count
If (objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Width >= objWord.InchesToPoints(MIN_LABEL_WIDTH) And
objDoc1.Tables.Item(1).Cell(rowCounter, colCounter).Height >=
objWord.InchesToPoints(MIN_LABEL_HEIGHT)) Then
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.InsertParagraphBefore()
'Code to deremine the value of txtLabel.
'Basically i have a loop here that loops through a bunch
of stuff and
'genearates a number of values for txtLabel.
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.Text = txtLabel
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.Cells.VerticalAlignment =
word.WdCellVerticalAlignment.wdCellAlignVerticalCenter
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.ParagraphFormat.Alignment =
word.WdParagraphAlignment.wdAlignParagraphCenter
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.Rows.Alignment = word.WdRowAlignment.wdAlignRowCenter
End If
Next colCounter
Next rowCounter
So basically it works, but the problem is that it only generates one page,
which is fine if the data i want to display is less than a page long.
However, if i have a lot of data to put on the document i need for it to open
as many pages as needed and right now it is not doing that.
Help please!
Thanks!
ok, what i am trying to do is, by using the Word Automation Porgramming
Objects, to dynamically create a Word document using VB.NET. Here is my code
so far:
Dim objWord As Word.Application
Dim objDoc0 As Word.Document, objDoc1 As Word.Document
Dim objTable As Word.Table
Dim objShape As Word.InlineShape
'Start Word and open the document template.
objWord = CreateObject("Word.Application")
objWord.Visible = True
objDoc0 = objWord.Documents.Add
objWord.MailingLabel.DefaultPrintBarCode = False
objDoc1 = objWord.MailingLabel.CreateNewDocument(Name:="5162")
objDoc1.Tables.Item(1).Range.ParagraphFormat.SpaceAfter = 0
objDoc1.Tables.Item(1).AllowPageBreaks = True
For rowCounter = 1 To objDoc1.Tables.Item(1).Rows.Count
For colCounter = 1 To objDoc1.Tables.Item(1).Columns.Count
If (objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Width >= objWord.InchesToPoints(MIN_LABEL_WIDTH) And
objDoc1.Tables.Item(1).Cell(rowCounter, colCounter).Height >=
objWord.InchesToPoints(MIN_LABEL_HEIGHT)) Then
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.InsertParagraphBefore()
'Code to deremine the value of txtLabel.
'Basically i have a loop here that loops through a bunch
of stuff and
'genearates a number of values for txtLabel.
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.Text = txtLabel
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.Cells.VerticalAlignment =
word.WdCellVerticalAlignment.wdCellAlignVerticalCenter
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.ParagraphFormat.Alignment =
word.WdParagraphAlignment.wdAlignParagraphCenter
objDoc1.Tables.Item(1).Cell(rowCounter,
colCounter).Range.Rows.Alignment = word.WdRowAlignment.wdAlignRowCenter
End If
Next colCounter
Next rowCounter
So basically it works, but the problem is that it only generates one page,
which is fine if the data i want to display is less than a page long.
However, if i have a lot of data to put on the document i need for it to open
as many pages as needed and right now it is not doing that.
Help please!
Thanks!