I need to place 3 things on this Word Doc. In this order:
-An Image;
-Some Text(justify);
-A table (Aligned with the text);
I'm using my code to place this in the order that I want, but when I open the .doc, the order is all messed up!
The table is the first thing to appear, followed by the text, and the image no longer appears.
Why? And how may I set the position or order of this objects?
My Currently Code:
Also, what would be the best way to place the text?
Because doing like i'm doing, it just print the last line of text...
Obs: I found something about Bookmark would that be my solution ? i'm trying to use it right now...
Here's an exemaple of the result:
-An Image;
-Some Text(justify);
-A table (Aligned with the text);
I'm using my code to place this in the order that I want, but when I open the .doc, the order is all messed up!
The table is the first thing to appear, followed by the text, and the image no longer appears.
Why? And how may I set the position or order of this objects?
My Currently Code:
Code:
Private Sub Command1_Click()
Dim Word_App As Word.Application
Dim Word_Doc As Word.Document
Dim Word_Table As Word.Table
Dim Word_Range As Word.Range
Dim iCount As Integer
iCount = 1
Set Word_App = New Word.Application
Set Word_Doc = Word_App.Documents.Add(DocumentType:=wdNewBlankDocument)
Set Word_Range = Word_App.ActiveDocument.Range()
'Insert the image
Word_Doc.Shapes.AddPicture FileName:="C:\p\53.jpg", Left:=100, Top:=0, SaveWithDocument:=True
'Insert some text
With Word_Range
.InsertParagraphAfter
.Font.Name = "Tahoma"
.Font.Size = 10
.Text = "Prezado<Field1> (<Field2>),"
.Text = "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT "
.Text = "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ."
.InsertParagraphAfter
.Text "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT "
.Text "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ."
.InsertParagraphAfter
.Text "TEXT TEXT TEXT TEXT TEXT TEXT ."
.Text " TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ."
.Text "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ."
End With
'Insert Table
Set Word_Table = Word_Doc.Tables.Add(Range:=Word_Doc.Range(Start:=1, End:=1), NumRows:=3, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed)
'Config Table
With Word_Table
If .Style <> "Tabela com grade" Then
.Style = "Tabela com grade"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
.ApplyStyleRowBands = True
.ApplyStyleColumnBands = False
End With
'Populate the table temporary with this text. It will be populated with data from DataBase.
Word_Table.Columns(1).Cells(1).Range.Text = "Débito"
Word_Table.Columns(2).Cells(1).Range.Text = "Valor"
Word_Table.Columns(3).Cells(1).Range.Text = "Juros/Multa"
Word_Table.Columns(4).Cells(1).Range.Text = "Total"
Word_Table.Columns(1).Cells(2).Range.Text = "<debito>"
Word_Table.Columns(2).Cells(2).Range.Text = "<valor>"
Word_Table.Columns(3).Cells(2).Range.Text = "<jurosmulta>"
Word_Table.Columns(4).Cells(2).Range.Text = "<total>"
Word_Table.Columns(4).Cells(1).Range.Text = "Débito"
Word_Table.Columns(3).Cells(3).Range.Text = "Total"
Word_Table.Columns(4).Cells(3).Range.Text = "<totalf>"
'Save the .Doc
Word_Doc.SaveAs FileName:="C:\p\TestandoPicture"
Word_Doc.Close False
Word_App.Quit False
End Sub
Because doing like i'm doing, it just print the last line of text...
Obs: I found something about Bookmark would that be my solution ? i'm trying to use it right now...
Here's an exemaple of the result:
Comment