Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Rotating Tables To Landscape In Word 97

I've tried doing it using this method

But the table end up with the columns in reverse order for me. Any tips or alternative methods.


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Printing Tables To A Landscape Label
I need to set up code to print two tables out of our database to a 1" x 2 5/8" landscape label. The label needs to print automatically when a membership card is scanned. Does anyone know how to do something like this in VB6?

VB, MS Word Macro - Prompt # Of Tables Wanted, Copy + Paste # Of Tables
I have a Microsoft Word document that contains a table with form fields.

I would like it set up so that when the user first opens up the document, Microsoft Word prompts the user "how many additional tables" they want in addition to the one that already exists in the document.

The macro would then select and copy, then paste the table "that many times" underneath.

Unfortunately I don't know much about Visual Basic. On the bright side, I do know how to make macros in Word. Can anyone here help me out?

Printing Landscape In Word
I want to send the landscape characters to a word document so that I can change the page orientation to landscape. Their Hex value is 1b 26 6c 30 4f. I have tried
chr(1b)& chr(26) & chr(6c) & chr(31) & chr(4f) and
&H1B& & &H26& & &H6C& & &H31& & &H4F&
but neither work along with some other combinations. I thought it would work like the new page chr(12) which works. Any ideas or thoughts are appreciated.

VB 6 And Word Object - Set Page To Landscape

I am dumping the contents of a recordset into a table in word and cannot work out how to set the page layout to landscape and to auto fit the columns or is it possible to set the width on each column separately.

Can anybody help?

sTemp = "Category" & vbTab & "Make" & vbTab & "Model" & vbTab & "Serial No" & _
vbTab & "Station No" & vbTab & "Details" & vbTab & "Location" & vbTab & "Warranty" & _
vbTab & "Warranty Left" & vbTab & "purchased" & vbTab & "Supplier" & vbCrLf & sTemp

oRange.ConvertToTable vbTab, , , , wdTableFormatColorful2

Thanks in advance


Resolved!!!! Landscape Mode Of Word Doc (Moderators Please Guide Me...)
I am not sure if this question is right for this forum. But, I just want to find something and I hope on fo you can answer my question.

I want to have one page set to "Potrait" mode and one page set to "Landscape" mode in the same document in Word. Is this possible??

If anyone knows a good Word forum, please guide me to it. I can post my question there.

Tables In VB And Word
Hi, I am trying to find a solution that allows me to create a table-like control taht my users can enter information in a MS Word document.

I will then retreave the text from the table or grid and send it to a text document using the open statement.

I've tried the two FlexGrids but I don't think that they are editable nor are they installed on most computers so my document won't be portable.

Any ideas?

Word Tables

I need to create a table in Word with one cell, then add the contents of another document (a .html-file) into the cell. How do I do it in Visual Basic?

Thanks in advance


Tables In Word VBA
Hi there I need to create a word table on the fly.

What I am doing is connecting to a sql database and returning a recordset. This recordset has 3 columns labelled Age, Name, Sex. However, the number of rows produced can vary e.g from 1 to 20.

I am not used to word macros, so any ideas would be greatly appreciated.


WORD, RTF, Tables
Can anyone help, or am I barking up the wrong tree.

I have created a document from an RTF template which contains a table. I want to look at one of the cells in my table, check the data in there and then import some text from a file or database in relation to it. Can it be done? When I go into the VB side of Word with my document open, there don't appear to be any objects to manipulate. This is all a bit new to me so your assistance would be most appreciated.

Best Regards


V.b. And Word And Tables
i am writing an application that creates word document, and i need to create a complex set of tables in the socument, attached is an example of the tables i wish to create, is this possible to automate, and then populate from an access database?

Word Tables
Hello all,

Request help.

Is there any way to insert Tables like MS Word in RichText box?
Is there any free OCX does that?

Please help....


Word Tables - PLEASE Help
Ok i have a little problem, i no how to draw a table into a word document from my VB application but i cant seem to get it to draw tables on the fly, i no its somthing silly im doing with the "range" at a guess, hope some one can help me, the following code is just a test but when i get it working ill be able to put it into practace.

Also any help on filling in the table and making the top row merg so that is only has one cell accross the table would be a big help

So it looks kinder like this


Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oRange As Word.Range

oWord = CreateObject("Word.Application")

oWord.Visible = True

oDoc = oWord.Documents.Add

Loop starts=====

oWord.Selection.Tables.Add(oDoc.Range, 4, 2)

Loop Ends =====

Word Tables

I have a macro in Word that is written in VB 6. That macro, among other things, is adding a table to a Word document and filling it with data. Now the thing is, sometimes the table is spanned over two pages (if it's to big to fit on one paper). I would like the table to only be on one page. Is there some property of the table object that makes the table fit on only one page?
Thanks in advance!

Tables In Word
I am trying to do something a little tricky with tables in a word document. Attached is an example of what i am trying to achieve. So far, i have created a table with 2 columns and 6 rows. I then used the split command , but as you can see from the second table in the document attached, it does not quite give me what i want. The first table in the document is the way i want it to look .....

Any suggestions?



VB6, Word And Tables
When I am parzing through a word document using the tables collection and a table is split over 2 pages. The table seems to be split in the collection. Very annoying when trying to loop through the table. Any ideas on how to get the table parts back as one?

Word Tables
Could anyone help me out with manipulating tables in Microsft Word.What i need to know is how to Insert/remove rows/columns and add text to particular cells etc

Tables In Word

I am quite new to the world of Visual Basic programming in Word. I have pasted a table of data from Excel into Word and I would now like to automatically select the data inside one of the cells and use that data as part of a new file name. I know that I can use ActiveCell in my VBA but can I assign the value in the active cell to an object.

Please Help


Adding Tables To Word
objWordDoc.Tables.Add(, 4, 5) = (???)
What item goes where ??? is to create a table with 4 rows and 5 columns

Working With Tables In Word From VB
how can I enter data to tables in MS-WORD from the VB code?

Creating Tables In Word Using VBA ?
i need to create multiple tables using vba in word. the problem which i face is that when i try to "copy" and then "paste" it in the same document, it creates another CELL rather than a table and then i becomes a problem for my program. then the second thing i tried was to create multiple table using "range" thingy but the control remained in the first cell and all other tables were being created within that first table. all i need is to create multiple tables in a single word document that i am working on. Need some guidance either in creating them in a different way altogether or moving the control/cursor to a new line after creating first table.

Help In Tables In Word Document

There are some columns in the grid which are hidden. Now i want to export this form to a word document. In the word document i am getting the hidden columns also, how do i avoid this

My code is :

For irowcnt = 0 To vsfgFoodComm.Rows - 1
For icolcnt = 0 To vsfgFoodComm.Cols - 1
If icolcnt = 0 And vsfgFoodComm.ColIsVisible(icolcnt) Then
.Tables(1).Cell(irowcnt + 1, icolcnt + 1).Range.InsertAfter vsfgFoodComm.TextMatrix(irowcnt, icolcnt)
ElseIf icolcnt = 1 And vsfgFoodComm.ColIsVisible(icolcnt) Then
.Tables(1).Cell(irowcnt + 1, icolcnt + 1).Range.InsertAfter vsfgFoodComm.TextMatrix(irowcnt, icolcnt)
ElseIf icolcnt = 2 And vsfgFoodComm.ColIsVisible(icolcnt) Then
.Tables(1).Cell(irowcnt + 1, icolcnt + 1).Range.InsertAfter vsfgFoodComm.TextMatrix(irowcnt, icolcnt)
ElseIf icolcnt = 3 And vsfgFoodComm.ColIsVisible(icolcnt) = True Then
.Tables(1).Cell(irowcnt + 1, icolcnt + 1).Range.InsertAfter vsfgFoodComm.TextMatrix(irowcnt, icolcnt)
ElseIf icolcnt = 4 And vsfgFoodComm.ColIsVisible(icolcnt) Then
.Tables(1).Cell(irowcnt + 1, icolcnt + 1).Range.InsertAfter vsfgFoodComm.TextMatrix(irowcnt, icolcnt)
ElseIf icolcnt = 5 And vsfgFoodComm.ColIsVisible(icolcnt) Then
.Tables(1).Cell(irowcnt + 1, icolcnt + 1).Range.InsertAfter vsfgFoodComm.TextMatrix(irowcnt, icolcnt)
ElseIf icolcnt = 6 And vsfgFoodComm.ColIsVisible(icolcnt) Then
.Tables(1).Cell(irowcnt + 1, icolcnt + 1).Range.InsertAfter vsfgFoodComm.TextMatrix(irowcnt, icolcnt)
ElseIf icolcnt = 7 And vsfgFoodComm.ColIsVisible(icolcnt) = True Then
.Tables(1).Cell(irowcnt + 1, icolcnt + 1).Range.InsertAfter vsfgFoodComm.TextMatrix(irowcnt, icolcnt)
End If

'If the value in the grid contains a "0" or null value then
With .Application.ActiveDocument.Tables(1)
Dim i As Integer
If .Cell(2, 2).Range.Text = "0" Or .Cell(2, 2).Range.Text = "" Then
For i = 1 To 7
.Cell(i, 2).Delete
If Trim(.Cell(1, 3)).Range.Text <> "" Then
GoTo DelB:
End If
End If
If .Cell(2, 3).Range.Text = "0" Or .Cell(2, 3).Range.Text = "" Then
For i = 2 To 7
.Cell(i, 3).Delete
If Trim(.Cell(1, 4)).Range.Text <> "" Then
GoTo DelC:
End If
End If

Calculating Tables In Word
I have a template in word that has a table where thought the use of a input form the client inputs what is being ordered and I want ti to calculate the total sale of that item being ordered.

My template is attached if anyone has any ideas that could assist me in this issue.

Any and all advice/criticism is more than welcome,


Formatting Tables In Word
I have a table that is 1x1 with two lines of text. I have formatted the table to be centered Horizontally and Vertically. That is great when both lines of text are used. I am using vb code from a user form to place the text to my book marks. There are two bookmarks in this 1x1 table on top of each other. How do I achieve a centered cell if only one line is filled in?

Attached is a screen shot of what I have done thus far.

Any help would be greatly appreciated.

Problem With Tables In Word
I have a Word document with various <<sqlData1 (2, 3, etc.)>> entries, some of which are in the text body, some of which are in a table. The VB code replaces the entries at runtime. The text body ones work fine, but the table ones always leave the last two characters (usually the >>) after the replaced text. Why is this, and what can I do to correct it?

Problem With Tables In Word
I'm tryin' to make a report in Word for which i'm using tables. The fact is that when i try to get out from a table, i can't because what happens is that another cell is added. Help me please.

Here is part of the code i'm using:

Set myWord = GetObject("", "Word.Basic")
myWord.AppMaximize ("Microsoft Word")
myWord.Insert "CELL"
myWord.formatparagraph Alignment:=1
myWord.FormatFont Points:="7", Font:="Courier New", Bold:=1
myWord.Insert "Productivity Avg"
myWord.formatparagraph Alignment:=1
myWord.FormatFont Points:="7", Font:="Courier New", Bold:=1
myWord.Insert "Production(Pcs)"

right after this i have to get out of the table but it doesn't allow me

Using VB To Delete Tables In MS Word
I'm using VB to build a new MS Word document from a MS Word template. The template has a series of tables that contain a header row and varying detail rows. A "custom" document is created by deleting detail rows in each table as necessary based on user-supplied parameters. If all detail rows are deleted from any table and only the header remains, the entire table is deleted. Everything works fine to this point.

The problem is that each table is seperated by a blank line. When empty tables are deleted, I end up with odd line spacing due to the blank lines. I can't figure out how to select the blank line after the table to delete it as well. Below is the code that I use to check for and delete the empty tables.

Any suggestions?



'Delete "Empty" Tables, the ones that have only 1 row (the header row)
For Each wdTable In wdNewDoc.Tables
If wdTable.Rows.Count < 2 Then
End If

Word Tables In Excel
Regarding my previous post asking how to bring data stored in Word tables into Excel.
I've gone ahead and implemented a strategy to first convert the tables into text and then to read the delimited text.

I'm having trouble specifying a Word table type
My code is as follows:

Private Sub ConvertProSum()
Dim word_app As Object
Dim tableCount As Integer
Dim tableTemp As Word.Table '<----- DOESN'T LIKE THIS
Dim rngTemp As Range
Dim i As Integer

On Error Resume Next

Set word_app = CreateObject("Word.Application") 'instance of MS Word
word_app.Documents.Open _
Filename:=Me.txtProSumPath.Text, _
Format:=wdFormatDocument 'opens Summary file

tableCount = word_app.ActiveDocument.Tables.count 'get # of tables in ProSum

For i = 1 To tableCount
Set tableTemp = word_app.ActiveDocument.Tables(i) 'target 1st, 2nd,... table

' convert to text: field=value pairs
Set rngTemp = tableTemp.ConvertToText(Separator:=wdSeparateByTabs)
Next i

word_app.ActiveDocument.SaveAs _
Filename:="LoadProSum.tmp", _
FileFormat:=wdFormatText 'save converted text as a temp file

word_app.ActiveDocument.Close False 'close Word
End Sub

How do I specify a word Table type in Excel?


WORD-VBA: Ranges And Tables
Hi all, I have a doubt about VBA for Word and ranges

Look, I have to insert a couple of tables into a word document, one below each other, to make this I am trying to do this way

Set oTable = Me.Range.Tables.Add(oRange, 1, 1)
With oTable
.Cell(1, 1).Range.Text = "Table 1"
End With

Set oTable = Me.Range.Tables.Add(oRange, 1, 1)
With oTable
.Cell(1, 1).Range.Text = "Table 2"
End With

But my problem, is that when I end to create the first table, the actual range is inside the cell of the table, so the second table in inserted INSIDE the cell, not below the firt table.

so, my question is, how can I, when I finish to create and edit a table, put the actual range below that table?

Thanks to all

Count Word Tables
Hi Folks,

I need to count the number of tables that exist within a word document, so that I can then define a loop to count through each table and extract certain values from each column. Opening Word is no problem, but the count method returns an error stating that the object is not supported.

Word is referenced in the project

Here is an example of the code

Dim controlword As Word.Application
Set controlword = New Word.Application
controlword.Documents.Open ThisWorkbook.Path & "" & "doc1.doc" controlword.Visible = True
MsgBox controlword.thisdocument.tables.count

Anyhelp would be much appreciated

Tables In Richtextboxes Like In Word
I want to be able to insert tables into my word processor like in word.
is there a way of doing this in a richtextbox in VB?

Populating Word Tables In Vb
Hi friends.

I need your help for a table I have created in word document .
Table contained on five columns and twelve rows . The last three columns are for rate values in local currencies , as it is a bidding price. Now what I want to automate in these three columns , a vb code which selects lowest value after I enter three different price rates. Further the selected lowest price need to change the font color from black to blue so that the lowest value can be sorted out easily without consuming time .
thanks for being with you guys.

Extracting Tables From Word With VB
I am thinking of making a program that would help me out extremely in my daily activities. I would like to know if it is possible to extract tables from word where I can pull a given table from a word document and either throw the contents into a database or into a file. I am thinking of writing this in VB, but I would like to know if it is possible, since I cant find any info about this in my programming books I turn to this forum.

Please provide me with some insite.

Any code would be greatly appreciated.

If you have any questions feel free to ask, i frequently check this forum.

Thanks to all that reply.

How To Insert Two Tables Into Word Doc Using VB
hi friends,

i wanna insert two tables one after the other in a word doc using VB. i know how to create word object in VB. and i am using the following code to insert tables.

wdapp.ActiveDocument.Tables.Add selection.range, 4, 1
wdapp.ActiveDocument.Tables.Add selection.range, 4, 1

but the above code is giving error at second line. it is able to create the first table but not able to create the second table. i think there is some problem with the range.
Please help me out........


Insert More Than 2 Tables Into Word Doc
hi friends,

i want to insert 3 tables into the word doc through VB one after the other.

i know that, to add we use

wdapp.activedocument.tables.add selection.range,2,3
wdapp.activedocument.tables.add selection.range,1,3
wdapp.activedocument.tables.add selection.range,2,2

in this way i am only able to insert one table, at the second line it is giving an error saying that table already exists in the location. here there is some problem with the range. can u resolve my problem.


VBA - Word - Working With Tables
Im trying to put a text into a table cell, but vb is puting the text outside the table.

How can i select what is the cell that to fill with the exact text?


Dim WordObject As Word.Application
Set WordObject = CreateObject("Word.Application")
Dim myRange As Word.Range

With WordObject
.Documents.Open App.Path & ""
.Visible = True
.Selection.Text = dt1.Value
.Selection.Text = lbl_nproposta.Caption
.Selection.Text = cmb_resp_mechsys.Text
.Selection.Text = lbl_interessada.Caption
.Selection.Text = txt_titulo_proposta.Text
.Selection.Text = cmb_resp_cliente.Text
.Selection.Text = txt_objeto.Text
.Selection.Text = txt_metodologia.Text
If Trim(fg2.TextMatrix(1, 0)) <> "" Then
Set myRange = .ActiveDocument.Range(Start:=.ActiveDocument.Bookmarks("metodologia_tabela").Start, End:=.ActiveDocument.Bookmarks("metodologia_tabela2").End)
.ActiveDocument.Tables.Add Range:=myRange, NumRows:=fg2.Rows + 1, NumColumns:=3
.ActiveDocument.Tables(2).Columns(1).Width = 40
.ActiveDocument.Tables(2).Columns(2).Width = 200
.ActiveDocument.Tables(2).Columns(3).Width = 200
Dim mycell As Word.Cell
Set mycell = .ActiveDocument.Tables(2).Cell(Row:=1, Column:=1)
.Selection.Range.Text = "Item"
End If

'Clipboard.SetData Picture1.Picture, vbCFBitmap
End With
'WordObject.ActiveDocument.PrintOut Background:=False
WordObject.ActiveDocument.SaveAs FileName:="x.doc"

Inserting Tables Into A Word Doc
I'm just getting the hang of Range and Table object but I'm having trouble creating two SEPARATE tables in an MS-Word Doc from a VB App. The code to create a table is given on MSDN as:

Set oDoc = ActiveDocument
Set oTable = oDoc.Tables.Add( _
Range:=oDoc.Range(Start:=0, End:=0), NumRows:=3, _

iCount = 1
For Each oCell In oTable.Range.Cells
oCell.Range.InsertAfter "Cell " & iCount
iCount = iCount + 1
Next oCell
oTable.AutoFormat Format:=wdTableFormatColorful2, _
ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True

Of course, it works great. BUT I want to create a separate table underneath this one. But when I try to create another table, it inserts it into the first cell of the existing one. I guess what I'm asking is how do I move the cursor past the first table I just created?


Word Tables And Cells
try recording a macro and looking at the VBA code:

ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=3, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _

MS Word Tables Very Slow From VB?
I have written an app in VB6 which creates reports in MS Word 97.

Each resultset record must appear in it's own table.

I tried creating and formatting the tables 'on the fly' from VB as I needed them, however this was horrendously slow even for small resultsets.

I had to resort to creating a word template with a few thousand ready made tables, writing the data to the number of tables required, then deleting the tables I hadn't used. This is quicker than creating the tables through automation but is still slow (not helped by having a 13MB Word file in a Citrix metaframe environment!).

It seems the slow part is writing the data to the table cells (needless to say all the data is converted to String before insert)

Has anyone managed to create similar reports in MS Word?

Any suggestions would be gratefully received.

Vba Word-nested Tables
i have created in word a nested table. outside table is 2x2, and in cell (row 2 column 2) i have a nested table which is 3x3. i am having trouble refering to the nested table via vba and make changes. can anyone provide the code whereby, i can make a reference to the nested table and modify cells in the nested table?

Multiple Tables In Word Using VB6
Ok I am trying to create mulitple tables in a word document created in a VB6 dll, on a server and save it.

I have tried the following code which works on my machine but not the server
Windows XP(workstation) and Windows 2000 server.

Tried the following two lines.

For some reason it just leaves the coursor in the table cell and creates a new table in that cell, which is what i want i want a new table created after it.
The follwoing line creates the table

Set table = objDoc.Tables.Add(objWord.ActiveWindow.Selection.R ange, irowcount + 1, 3)

Any help on hwo to move out of the table to create a new one below would be great, i have already spent one day on this not happy.

Thanks Craig

How To Parse Tables Of Word Doc Using Vb
i m facing a problem while parsing a table in word doc.
i have a test1.doc which is having a table with multiple rows and columns having some data in it.
when i use the below code all the content is converted into a string where i find some junk character coming in between the text. Is there a solution to parse through the cells of a table in a word doc. using VB?

i would be immensely gratified by your quick reply.
thanks & regards,

Code:Private Sub Command1_Click()
Dim file_contents As String
Dim a As Integer
' Read the text contents of a Word file.
file_contents = GrabWordFile("test1.doc")
'MsgBox file_contents
End Sub

Private Function GrabWordFile(ByVal file_name As String) As _
Dim word_server As Object ' Word.Application
    ' Start thue Word server.
    Set word_server = CreateObject("Word.Application")
    ' Open the file.
       word_server.Documents.Open _
        FileName:="d: est1.doc", _
        ConfirmConversions:=False, _
        ReadOnly:=False, _
        AddToRecentFiles:=False, _
        PasswordDocument:="", _
        PasswordTemplate:="", _
        Revert:=False, _
        WritePasswordDocument:="", _
        WritePasswordTemplate:="", _
    ' Return the document's text.
    GrabWordFile = word_server.ActiveDocument.Content.Text
    ' Close the document without prompting.
    word_server.ActiveDocument.Close False
End Function

Formatting Tables In Word 97
I have a few complex formatting rules to apply to some tables that are being created from a XML and Excel data sources. The problem is that the data source contains some, but not all formatting infomation/rules etc. So I have some of this in VBA aswell. Has anyone a good techniques for formatting tables. Some reasons why they use a particular method would be useful.



Word Tables At 90 Degrees?
Anyone ever written a function to transpose a table with the objective of rotating the table to 90' ?


V.b. And Word And Complex Tables
i am tring to automate certain types of document creation, and in one of my documents, i have a complex table, i am new to v.b., and have no idea of how to make a table like the ones attached. I can do all the basica table functions fine, any suggestions?

Handling Word Tables
I need an ActiveX Component that takes a string and a file path. This component would open the file and put the string into a cell(x,y) that exists in the file. Someone know how to do it??? Thanks

Creating Tables In MS Word
Does anyone have a piece of code that shows how to create a table in word using vb code? I've gotten pretty good at formatting text in word from vb, but for my current project I would like to create a table and insert some values into the cells of that table from vb code. I've read the help files but they mainly deal with the formatting and obtaining of data in the table, not the actual creation of a table. Thanks in advance for any help!


More Trouble With MS Word Tables
Thanks to sotoasty, I have got my code (which i show below) creating the table I need in Word and filling cells with data. Now then, let's say I exit Word but leave my program still running. I hit my report button again to make Word come back up with the table and all, but i get this error instead...

Method "Add" of "Tables" Failed.

I only get this error after the program has launched Word once already, and I ONLY get it if this table is involved. I tried removing the line of code below (which draws the table) and I was able to run Word over and over without this error. Any ideas?

wrdapp.Selection.Tables.Add Range:=Selection.Range, NumRows:=31, NumColumns:=5,DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed

Creating Tables In MS Word
I want to know about the APIs used/methods to create tables in MS WORD using VISUAL BASIC.

Please provide me the answer as soon as possible.

Inserting Images && Tables Into Word
Using Visual Basic 6, importing into word

My situation is this: I'm creating a packing slip based on information I'm taking out of a .csv file. I need to take this information, and insert it into word. I need some basic formatting but nothing too fancy, which leads me to question #1:

How can I create a template / table containing my data in a new word document?

Next, I need to insert a simple image at the top of the page, it is basically a letterhead. I have the .jpg file. This is question #2:

How can I insert a .jpg file at the top of the page of a word document?

Thanks for any help. Much appreciated.

Copyright 2005-08, All rights reserved