shlomiassaf
09-02-2007, 07:57 AM
Hi,
I have a program that creates text boxs into a word document.
Due to size limit I can only put 6 textboxs in 1 page so I create new pages.
The thing is that it always put them in the same page even though it does create the new page...
Also, the page with the textboxs is always last... meaning it creates the new page above the last page...
here is the code:
Public Function WordMake()
Dim objWd As Word.Application
Dim objShape As Word.Shape
Counter = 1
Hi = 245
Wd = 255
BoxCounter = 1
Set objWd = CreateObject("Word.Application")
With objWd
.Visible = True
.Documents.Add DocumentType:=wdNewBlankDocument
'Total_TEXTBOX_Needed is known from a procedure before this function
Do Until Counter = Total_TEXTBOX_Needed
If BoxCounter = 1 Then
Lf = 37
Tp = 40
ElseIf BoxCounter = 2 Then
Lf = 37
Tp = 297
ElseIf BoxCounter = 3 Then
Lf = 37
Tp = 554
ElseIf BoxCounter = 4 Then
Lf = 309
Tp = 40
ElseIf BoxCounter = 5 Then
Lf = 309
Tp = 297
ElseIf BoxCounter = 6 Then
Lf = 309
Tp = 554
End If
BoxCounter = BoxCounter + 1
'HERE IF THERE IS MORE THEN 6 IT CREATES A NEW PAGE
If BoxCounter = 7 Then
.Selection.InsertBreak Type:=wdPageBreak
BoxCounter = 1
End If
'HERE IT CREATES THE TEXT BOX WITH THE NEEDED POSITIONING
Set objShape = .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, Lf, Tp, Wd, Hi)
Set objTextFrame = objShape.TextFrame.TextRange
With objTextFrame
.Text = "PUT SOME DATA IN TEXTBOX"
End With
Counter = Counter + 1
Loop
End With
Set objShape = Nothing
Set objWd = Nothing
End Function
Any clues what I do wrong?
Thanks,
Shlomi
I have a program that creates text boxs into a word document.
Due to size limit I can only put 6 textboxs in 1 page so I create new pages.
The thing is that it always put them in the same page even though it does create the new page...
Also, the page with the textboxs is always last... meaning it creates the new page above the last page...
here is the code:
Public Function WordMake()
Dim objWd As Word.Application
Dim objShape As Word.Shape
Counter = 1
Hi = 245
Wd = 255
BoxCounter = 1
Set objWd = CreateObject("Word.Application")
With objWd
.Visible = True
.Documents.Add DocumentType:=wdNewBlankDocument
'Total_TEXTBOX_Needed is known from a procedure before this function
Do Until Counter = Total_TEXTBOX_Needed
If BoxCounter = 1 Then
Lf = 37
Tp = 40
ElseIf BoxCounter = 2 Then
Lf = 37
Tp = 297
ElseIf BoxCounter = 3 Then
Lf = 37
Tp = 554
ElseIf BoxCounter = 4 Then
Lf = 309
Tp = 40
ElseIf BoxCounter = 5 Then
Lf = 309
Tp = 297
ElseIf BoxCounter = 6 Then
Lf = 309
Tp = 554
End If
BoxCounter = BoxCounter + 1
'HERE IF THERE IS MORE THEN 6 IT CREATES A NEW PAGE
If BoxCounter = 7 Then
.Selection.InsertBreak Type:=wdPageBreak
BoxCounter = 1
End If
'HERE IT CREATES THE TEXT BOX WITH THE NEEDED POSITIONING
Set objShape = .ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, Lf, Tp, Wd, Hi)
Set objTextFrame = objShape.TextFrame.TextRange
With objTextFrame
.Text = "PUT SOME DATA IN TEXTBOX"
End With
Counter = Counter + 1
Loop
End With
Set objShape = Nothing
Set objWd = Nothing
End Function
Any clues what I do wrong?
Thanks,
Shlomi