Hi guys, I need to learn how to create a MS-Word Table using the language VB6.
This is all I could do so far: -
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
-
-
Set Word_App = New Word.Application
-
Set Word_Doc = Word_App.Documents.Add(DocumentType:=wdNewBlankDocument)
-
Set Word_Table = Word_Doc.Tables.Add(Word_App.Selection.Range, 3, 5)
-
Set Word_Range = Word_App.ActiveDocument.Content
-
-
Set Word_Doc = Word_App.ActiveDocument
-
Set Word_Table = Word_Doc.Tables.Add(Range:=Word_Doc.Range(Start:=0, End:=0), NumRows:=2, NumColumns:=2)
-
iCount = 1
-
-
Word_Doc.Tables(1).AutoFitBehavior (wdAutoFitContent)
-
-
-
For Each Cell In Word_Table.Range.Cells
-
Cell.Range.InsertAfter "Hello World " & iCount
-
iCount = iCount + 1
-
Next Cell
-
-
-
Word_Doc.SaveAs FileName:="C:\p\Test"
-
Word_Doc.Close False
-
Word_App.Quit False
-
-
End Sub
I'd like to know if this is the best way to create the table. Also I'd like to know how to set the column Width, borders and colors and how may I change the space between cells ?
Thanks
9 5664 Rabbit 12,516
Recognized Expert Moderator MVP
The easiest way to find out the code to do that is to open word and record a macro of you doing all that manually. Then you can just copy and modify the code the macro created for you.
How may I do that? Sorry I never used it in ms-word x-x
Rabbit 12,516
Recognized Expert Moderator MVP
That depends on what version of word you are using. In 2007, you click developer and then click record macro.
It's Office 2007, I already checked the checkbox to show the Developer Bar.
Now I have two options: Button & Keyboard. Wich one should I pick ? Also, where am I supposed to get the code after the record?
Thanks
Rabbit 12,516
Recognized Expert Moderator MVP
It doesn't matter which you pick because you don't actually need to save the code or document once you're done. You don't even have to pick one.
After you finish recording, you can see the code for the macro by clicking macro. Select the macro you just recorded. Click edit. It will take you to the code.
Thanks, worked perfect !! But what IF I wanted to change manually the size of the rows and cells like Height and Width ? How could I do that?
Rabbit 12,516
Recognized Expert Moderator MVP
You don't have to use the code it creates exactly. Just use it as a template for the methods and objecst you need to use. You can plug in variables for any of the hard-coded values such as the height and width.
Thanks man, you're awesome !! Just one more little thing, I need to understand the syntax. When I'm ONLY creating the Table, it works perfect. But if I try to insert a picture before that I create the table. An error happens:
This is the code that I use to insert a picture. -
Word_App.Selection.InlineShapes.AddPicture FileName:="C:\Documents and Settings\All Users\Documentos\Minhas imagens\Amostras de imagens\Inverno.jpg", SaveWithDocument:=True
-
When I use the Word_App again to insert values into the table, the error is fired. Why? -
Word_App.Selection.TypeText Text:="Débito"
-
Word_App.Selection.MoveRight Unit:=wdCell
An error is fired, like: The required member of the collection does not exists.
Why?
Rabbit 12,516
Recognized Expert Moderator MVP
Most likely the selection has changed.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: nish |
last post by:
Hi,
I am struggling with this code. I am trying to create 3 separate
tables and print them in word, however I end up with 1 big table and 1
nested table inside and 1 more nested table within...
|
by: garth |
last post by:
I created a Crystal Report that looks perfect when exported to Word,
but the box and lines I use to simulate a table in the Crystal Report
does not get created as a table in Word. Instead, it is...
|
by: Ken Swinton |
last post by:
I am developing a program that gathers inspection visit details and save them in string variables. I need to output this information to a Word template. I have attempted to use Bookmarks, so far...
|
by: surveyor |
last post by:
Hello everyone,
I have used Microsoft Word 10 library for creating word document in VB6. But I see it is very slow. Please tell me how I can do faster?
For creating document content I use...
|
by: prashantmalikiec |
last post by:
Hi all,
i am new to .net and my problem is that i am not able to create a ms word document using .net.
i dont know how to write some text(hello world) into the word document
thanks,...
| |
by: menelty |
last post by:
Hi,
I have been trying to create a word document using vb.net. I have
several fields I wish to populate so I am using a MS Access back end
to spit out the requested data for these fields as the...
|
by: parallax |
last post by:
Hi guys,
i would like to make
create temporary table pagamentos SELECT d.name, SUM(advanced) AS total_advance, f.salario FROM data d JOIN empregados f ON f.name = d.name where MONTH(d.date) = 04...
|
by: LegalIT |
last post by:
Hello,
I am creating a Word table using a VB.net application. I have it working with the following declaration:
Dim table As Word.Table = myRange.Tables.Add(myRange, intRowCount, 5)
I...
|
by: pnalla |
last post by:
hi
how to create a word documetn using Excel macros..
i have some code but it crating a word document but it isnot close properly
whats the proble.
please suggest me.
thanks
prasad
|
by: impin |
last post by:
word document should display the details about the candidate.
<?php
include("config.php");
//$table = 'table_name';
$outstr = NULL;
$id = $_GET ;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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...
|
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...
|
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...
|
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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |