473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Order the objects on the word doc

28
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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim Word_App            As Word.Application
  3. Dim Word_Doc            As Word.Document
  4. Dim Word_Table          As Word.Table
  5. Dim Word_Range          As Word.Range
  6. Dim iCount              As Integer
  7.  
  8. iCount = 1
  9. Set Word_App = New Word.Application
  10. Set Word_Doc = Word_App.Documents.Add(DocumentType:=wdNewBlankDocument)
  11. Set Word_Range = Word_App.ActiveDocument.Range()
  12.  
  13. 'Insert the image
  14. Word_Doc.Shapes.AddPicture FileName:="C:\p\53.jpg", Left:=100, Top:=0, SaveWithDocument:=True
  15.  
  16. 'Insert some text
  17. With Word_Range
  18.     .InsertParagraphAfter
  19.     .Font.Name = "Tahoma"
  20.     .Font.Size = 10
  21.     .Text = "Prezado<Field1> (<Field2>),"
  22.     .Text = "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT "
  23.     .Text = "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ."
  24.     .InsertParagraphAfter
  25.     .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  "
  26.     .Text "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ."
  27.     .InsertParagraphAfter
  28.     .Text "TEXT TEXT TEXT TEXT TEXT TEXT ."
  29.     .Text " TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ."
  30.     .Text "TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT ."
  31. End With
  32.  
  33. 'Insert Table
  34. Set Word_Table = Word_Doc.Tables.Add(Range:=Word_Doc.Range(Start:=1, End:=1), NumRows:=3, NumColumns:=4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
  35.         wdAutoFitFixed)
  36. 'Config Table
  37. With Word_Table
  38.     If .Style <> "Tabela com grade" Then
  39.         .Style = "Tabela com grade"
  40.     End If
  41.     .ApplyStyleHeadingRows = True
  42.     .ApplyStyleLastRow = False
  43.     .ApplyStyleFirstColumn = True
  44.     .ApplyStyleLastColumn = False
  45.     .ApplyStyleRowBands = True
  46.     .ApplyStyleColumnBands = False
  47. End With
  48.  
  49. 'Populate the table temporary with this text. It will be populated with data from DataBase.
  50. Word_Table.Columns(1).Cells(1).Range.Text = "Débito"
  51. Word_Table.Columns(2).Cells(1).Range.Text = "Valor"
  52. Word_Table.Columns(3).Cells(1).Range.Text = "Juros/Multa"
  53. Word_Table.Columns(4).Cells(1).Range.Text = "Total"
  54. Word_Table.Columns(1).Cells(2).Range.Text = "<debito>"
  55. Word_Table.Columns(2).Cells(2).Range.Text = "<valor>"
  56. Word_Table.Columns(3).Cells(2).Range.Text = "<jurosmulta>"
  57. Word_Table.Columns(4).Cells(2).Range.Text = "<total>"
  58. Word_Table.Columns(4).Cells(1).Range.Text = "Débito"
  59. Word_Table.Columns(3).Cells(3).Range.Text = "Total"
  60. Word_Table.Columns(4).Cells(3).Range.Text = "<totalf>"
  61.  
  62. 'Save the .Doc
  63. Word_Doc.SaveAs FileName:="C:\p\TestandoPicture"
  64. Word_Doc.Close False
  65. Word_App.Quit False
  66.  
  67. End Sub
  68.  
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:

Aug 30 '13 #1

✓ answered by Rabbit

I don't do a lot of word automation so I can't be sure, but I'm guessing it's because you chose your range before doing anything. Therefore, the range is the beginning of the document. Which means you insert an image at the beginning. Then you write text over the image at the beginning. Then you insert a table at the beginning. You should try redefining the range after each addition to the document.

3 1327
Rabbit
12,516 Expert Mod 8TB
I don't do a lot of word automation so I can't be sure, but I'm guessing it's because you chose your range before doing anything. Therefore, the range is the beginning of the document. Which means you insert an image at the beginning. Then you write text over the image at the beginning. Then you insert a table at the beginning. You should try redefining the range after each addition to the document.
Aug 30 '13 #2
Ghaleon
28
Thanks again³.
Yes, But I don't know how to set the range to the end of the text... I'm trying to understand this Bookmarks, but I'm not going very well ;x

UPDATE 2
Its over haha ;D Thanks so much !!!!
Finally !

I did as following for those who may be in the same situation as mine:
Expand|Select|Wrap|Line Numbers
  1. Word_Doc.Bookmarks.Add("NameOfTheBookmark")
OK, now you just created a bookmark with the name you wanted, now to insert an object AFTER that bookmark, in my case, it was a table:
Expand|Select|Wrap|Line Numbers
  1. Word_Table = Word_Doc.Tables.Add(Word_Doc.Bookmarks("NameOfTheBookmark").Range,...
DOne !! HeHe xD
Aug 30 '13 #3
Rabbit
12,516 Expert Mod 8TB
Glad you got it working. Good luck with the rest of your project.
Aug 30 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Luther Baker | last post by:
Hi, Is the order of initialization guaranteed for static members as it is for instance members? Namely, the order they appear the in the declaration? ie: foo.h:
6
by: kobu.selva | last post by:
I was recently part of a little debate on the issue of whether constants and string literals are considered "data objects" in C. I'm more confused now than before. I was always under the...
10
by: Diego F. | last post by:
Hello. I need to store custom objects in a SQL Server 2000 table. Which is the easiest way to do it? Do I need to write methods to store each attribute separately from C# app to the table and the...
0
by: joseph speigle | last post by:
hi, To see the query results in native language see http://database.sarang.net/?inc=read&aid=5368&criteria=pgsql&subcrit=qna&id=&limit=20&keyword=&page=1 the simpler url is ...
2
by: christopherkilmer | last post by:
I've googled my brains out and haven't found the answer yet, so... I have a WebMethod that accepts an array of Order objects as a parameter. I cannot figure out how to send an array to the...
16
by: mdh | last post by:
May I ask the group the following: (Again, alas , from K&R) This is part of a function: while ( ( array1 = array2 ) != '\0' ); /* etc etc */ Is this the order that this is evaluated? ...
2
by: rmfoley | last post by:
All, I would like to create a professional looking cover sheet with information loaded from an MS Access Report. I created the cover sheet in MS Word that includes my company logo, etc. My...
6
by: MayBoy | last post by:
Hi There I am trying to use the Goto method of the Word ActiveX object. I am trying to open a document and go to a named bookmark. If I use this code in VB it works, so I'm sure the approach is...
6
by: marktxx | last post by:
Although the C90 standard only mentions the use of 'signed int' and 'unsigned int' for bit-fields (use 'int' at your own risk) and C99 adds _Bool. It seems that most compilers create the size of...
16
by: desktop | last post by:
I have implemented a red-black tree which is used for std::set. In the C++ standard 3 different insert methods are specified for the associative container. But as i see it insert adds an object...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.