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

Extract Text From Table In Word

I've been skimming through the threads and couldn't find QUITE this question.

I have a word document, with text and tables here and there (I don't know where they are in the document - they're spread throughout it).

I want to know:
1) How can I find the first table, then the next then the next etc...
2) Can I just collect ALL of the tables in the word documents into one object?
3) Once I find a table, how can I extract text from a specific cell in it.
Maybe go over ALL the rows then ALL the cells and look for the text.

How can I do that?

Thanks a lot people!
You're great!

- M00gl3

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
To Extract The First Word From A Text Box
I need to extract the first word from data in a text box (up to the first space) to use in an sql statement. What is the best way to do this?

To Extract The First Word From A Text Box
I need to extract the first word from data in a text box (up to the first space) to use in an sql statement. What is the best way to do this?

Extract Text From Word Document
Hello all, I was wondering if anyone knows how to extract the text from a word document. The format is not important but I wish to reatin the whitespace, (tabs, spaces, newlines).

I've found lots of examples on how to save and create a word document but nothing on extracting text. Thanks for your help.

Extract Text From Word Document.
I would like to write a class in VB 6.0, to extract text content from MSWord documents. Can anyone give me inputs on how to do this ?


How Can I Extract Text From A Word Document TextBox
i have been working on word Document files.

each document has same text format.

i m using the code below to extract text from it,


Dim sFileName As String 'Name of files within the folder will be stored
Dim i As Integer 'This will count the files read***
Dim wrd As Word.Application
Dim wrdCount As Long 'Number of characters within the file
'Get the first file with extension "DOC" ***
sFileName = Dir$("C:Virology*.DOC") '***
Do While sFileName <> "" '***
Set wrd = New Word.Application 'Create obj of word application
wrd.Visible = False
wrd.Documents.Open "C:Virology" & sFileName
wrdCount = wrd.Documents(1).Characters.Count
Text1.Text = Text1.Text & vbCrLf & i & wrd.Documents(1).Range(0, wrdCount).Text
Set wrd = Nothing
sFileName = Dir$ '***
i = i + 1

This works good for all the characters in the document but the problem rises when word textbox appears in the document.

Replace Text In A Table In Word

I'm using a word template in which i want to replace a certain word at a certain position for a newly created table.
How can i do this.

I have used this part of the code to find:

With objWord.ActiveDocument.Content.Find
.Text = table"
With .Replacement
End With
.Execute Format:=True, Replace:=wdReplaceAll
End With

This does nothing then finding the word "table" but i want to create a selection or range so the i can replace this word for a table with for example 3 rows en 3 colums.

Can anyone help me out?

Kind regards,


Extract Each Word From A String And Print One Word Per Line.
I have a textbox that contains a string(can be any number of words).

How do i extract each word from the string and
print one word per line onto the form? e.g.

Hi can someone please help me

Print to form:


Selecting Text In A Word Table Cell
This has probably been answered many times before but I can't find the solution. I need to insert some text into a Word table and then change the font without affecting the text that was already in the cell. My code will look something like this:

Set oWord = CreateObject("Word.Application")

' Create a new Word document based on template
oWord.application.Documents.Add App.Path & ""
oWord.Visible = True

With oWord.ActiveDocument.tables(1) ' First table in Word template
.cell(1, 2).range.insertafter "Temp 0001"
.cell(2, 1).range.insertafter " " & cmbCustomers
.cell(2, 2).range.insertafter vbCrLf & txtDrawingNo
.cell(2, 4).range.insertafter vbCrLf & txtWorksOrderNo
.cell(3, 1).range.insertafter " " & txtCustOrderNo
.cell(4, 1).range.insertafter vbCrLf & txtRequiredBy
.cell(4, 2).range.insertafter vbCrLf & txtDescription
End With

I guess I need to select the text I've just added and then apply the font formatting I need, but I can't quite work out the syntax to select just the new text and exclude the original contents of the cell. Thanks!

Export Text To Table In Word Document
I have an application in VB6 that perform some basic calculations. The calculations themselves are not particularly difficult, but are onerous when you have to repeat them again and again and put the results into a letter. The app works fine.

However, I would like some additional functionality whereby at the click of a button a user could export the results straight from the app into certain cells of a table in the Word document.

The document is a standard template - in other words it will always be the same.

However, i haven't the faintest idea how to approach it. I imagine I could get VB to query the document somehow and then insert data after it finds certain words. Could anybody please point me in the right direction?

Inserting Text In Table Created In Ms Word Using Vb
hai i have got 1 solution for the question post releating to creation of table in ms word which i am trying out ok now i have another doubt after creating table i have to insert text in that table and merge the table and do other formating like making bold and also to move the table

Word: How To Replace Text In A Table In A Header

In a Word document exists a table in a header. How can I select text in a cell of this table and replace it with something else?

Thanks for your help!

Edited by - ELOOP on 2/17/2006 6:22:38 AM

Setting Text Properties In Word Table

i need to set some text to bold inside a cell of a word table
i'm using vb6.

attached is the sample code.

        Set oTable = oDoc.Tables.Add(oDoc.Bookmarks("endofdoc").Range, 5, 2)
        oTable.Range.ParagraphFormat.SpaceAfter = 6
        oTable.Borders.Enable = False
        oTable.Cell(i%, 2).Range.Text = "Text1. Text2"
        oTable.Cell(i%, 2).Range.Font.Underline = False

in the text property of the cell, i need to set "Text1" to bold,
and leave "Text2" as is, with regular font.

any idea how to do this? any help would be greatly appreciated.

How Can I Fill Out A Table In A Word Document With The Text Of Textboxes Using Vb6?
i have a command button on my form and 6 textboxes as well (text1,text2,...,text6) and also there is a word document called mike.doc at C:mike.doc. this word document has only one empty 2x3 table in.


what i want to do is:


cell[1]= text1.text

cell[1]= text2.text .............................


whats the code to do that?

i have searched everywhere, nobody has helped so far with this, nobody knows.

thanks in advance.

Word Object: Accesing Text In Table: URGENT!

How do I access the text in a cell of my table?

For instance if i have a table with more than one row, and i need to know the value (text) which is present on column 1 of row 4.

I went as far as:

but then i don't know the attribute which holds the text value...

Can you help me please?

Changing Text Orientation/Direction In Table Cell - VBA Word Automation
I need to change the text direction/orientation to 90 degrees in a table cell in a Word document using automation. I know how to achieve this manually.

Right click on a table cell, select Text direction, in the window: select the orientation you want.

The same result I need to achieve through VBA automation. I am using Word 2003 & VB 6.

Could you please help me out in this regard ?
Thanks in advance.

Extract Dates Out From A Particular Table
How can i extract a list of dates out and store it in an other table ??

For example, Table A have

Date Total Amount
------ ----------------
01/04/02 30
01/04/02 40
01/04/02 20
02/04/02 20
02/04/02 30
03/04/02 40
04/02/02 25

and i want it to store in table B as

Date Total Amount
------ ----------------
01/04/02 90
02/04/02 50
03/04/02 40
04/02/02 25

Extract 3 Big Values From Table In SQL

I want to extract the 3 big values between 90 and 100 from my database(Access) Throught SQL.
I have this code:

VB Code:
sql = _     "select pontosind as Totais" & _     " from exposicao" & _     " WHERE pontosind >=  '90' " & _     " ORDER BY Totais desc "

but this code only give me the values >="90"

Any suggestion please?


Html Table Extract
does any one have any code snippet to extract all tables and data from html. I have the html in a string variable and need to get all the tables from it.


Extract HTML Table
I want to Extract the data from the HTML table including the links from the following website using a function. The function should connect to the website, retrieve the html source (this is already done), Scan the table, retrieve the data in a tabular form. Any ideas..thats the website.,2,3

Extract Data From SQL Table
I am developing in VB6 and using MS SQL 2000 as the database engine.
My shipping SQL table has the following fields
1. ContainerReference
2. BoxSize
3. Product
4. BoxReference
For the query I want to know how many of each Box-Size is scheduled for a specific  container.
Each box has a unique Reference
I have tried multiple variations of
CODE    SumStr = "SELECT  count(BoxReference) AS totpersize " _
        & "FROM shipping  WHERE ContainerReference = '" & Con.text & "'" _
        & " GROUP BY BoxSize
    Set SumrS = connDB.Execute(SumStr, , adCmdText)

debug.print "ContainerReference: " & con.text

Do Until SumrS.EOF
   Debug.Print  SumrS.Fields(0).value, SumrS.Fields(1).Value

How To Extract XML Data To SQL Database Table Using DTS
Does anyone know how to extract the info from an XML file to an SQL db table using DTS? I have the .xml file, .dtd file, and the sql table with matching fields.

I found an article on Microsoft's site explaining the 3 methods.


Below is the code Microsoft provided:

Set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad")
objBL.ConnectionString = "provider=SQLOLEDB.1;data source=MyServer;database=MyDatabase;uid=MyAccount;pwd=MyPassword"
objBL.ErrorLogFile = "c:error.log"
objBL.Execute "c:customermapping.xml", "c:customers.xml"
Set objBL = Nothing

I added the code to an .aspx page and used the <script language="VBScript"> tag. Microsoft's page said to save it as a .vbs document.

I tried the this method and got a message that the ActiveX component couldn't create the SQLXMLBulkLoad object. I'm not sure if I did it wrong or if the permissions on the server [I use shared hosting svc].


The .exe option isn't appropriate for me because I'm using a shared hosting service and can't execute and .exe applications.


I've exhausted the Google search and can't find a script for this. I'm a novice so please include the complete script including any page beginning and ending tags (<%, %>, etc.)

VB 5.0 To Extract Info From Access Table
Trying to pull info from access table named acclabel and field name 4digcode using VB 5.0. I want to find a match for the MyStr string and pull out the associated AccName. I keep getting a syntax error (missing operator) in query expresion '4digitCode = '1212". The code is as follows.


Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim MyStr As String

MyStr = "1212"

Set dbs = OpenDatabase("c:vbinvenVB.mdb")
Set rst = dbs.OpenRecordset("Select AccountName from acclabel Where 4digitCode = '" & MyStr & "'", dbOpenDynaset)
MsgBox "The AccountName is: " & rst.Fields(0).Value

How To Extract Data From Table In Treeview Into Msflexgrid..
hi guys..i'm new in i have a problem..let me explain..i have 2 treeview and the second one is msflexgrid..

treeview have 2 tables for examples:...
1) Table Bank = 5 column
2) Table Shop = 3 column

Whats make me stuck now is I cannot make the flexgrid flexible for both table. Wat I mean here is how to make when I click table Bank, the flexgrid will show 5 column and same thing happen when I click table Shop, it will display 3 column. I do not know how to make the Flexgrid automatically generate the column base on the table read.

Plzz guys...I need ur help...My dateline is very near...

Extract A Word From A Web Page...
How would I go about getting a single word from a web page? Lets say I go to and want to get the amount for icoins (points) that the user currently has and display it in a text would I do that?

Extract Data From Word
Hi Guys,
I'm getting stuck on a little problem here:
I want to extract variable length data from a Word doc, I want to be able to create a string of all of the text starting below the greeting line in a letter of "Dear So & So" and finishing at the end of the line above "Yours sincerely" so I can do things with it in VB.
I'm a newbie to VBA, I've searched various forums but can't find an answer anywhere.
I can do the find for the start and finish of the document area concerned, but I don't know how to tell VBA where these start/finish points are, and how to copy a selection into a variable, or some format that I can then parse etc in VB.
Any help would be much appreciated.

HOW To Extract Word From A Sentence?
For example:
if user type "I love icecream"
how do i extract each word and put "I", "love", "icecream" into 3 different variables?
a="I" B="love" C="icecream"

Extract Bookmarks Value From Word.doc
Anybody please help me out how to extract bookmarks values from a word doc?

I have a word document with many bookmarks field named from Text1, Text2, Text3....etc.

What I did was:

Dim w As Word.Document
Dim a As Word.Application
Dim output1 As String

Set a = New Word.Application
Set w = New Word.Document
Set w = a.Documents.Open("c:my document est303.doc")

output1 = w.Bookmarks.Item(1) -> This only retreive BookMarks name as "Text1" The "Text1" current contains value "ABC Company". How to extract value from "Text1"?


Extract MS Word Information

I have several (well, several hundred) word documents. I need to extract information from each such as Author, Date Created etc... how would I go about doing this for a single document?


Extract Data To Word
Hi there,
does anyone know of a compent that will allow me to place data I have in a Word document and save it from jmy vb application

Cheers in advance

Extract Bookmarks Value From Word.doc (part 3)
Hi RobDog888,

Thank you for your speedy response! ButI still get the same error.

1) How to iterate through the collection?

Label1.caption =””
For i = 0 to 41
Labe1.caption = Label1.caption ^ w.Bookmarks(i).Range.Text ^ chr(13)

Next i

The “for loop” does not work for w.Bookmark(i).Range.Text -> because Bookmarks is an object (or collection)?

Perhaps something like the following (I think)??

Dim cntrlItem as ?? (control, index…etc)
For each cntrItem IN ?? (collection, ?)

Next cntrlItem

Can you or someone fill the “??” blank?
Thank you.

Extract Bookmarks Value From Word Doc (Solved!)
Thank you very much. It works perfectly!!!!!

Extract Bookmarks Value From Word.doc (part 2)
Dim w As Word.Document
Dim a As Word.Application
Dim output1 As String

Set a = New Word.Application
Set w = New Word.Document
Set w = a.Documents.Open("c:my document est303.doc")


Registered: Apr 01
Location: Los Angeles, CA.
Posts: 2625

visual basic code:--------------------------------------------------------------------------------
msgbox w.Bookmarks("Text1").Range.Text


Thank you very much, RobDog888.

Part 2:

I have about 42 bookmarks fields in a word doc. -> output1 = w.Bookmarks.Count /** to get the number of bookmarks in the doc.

Now I need to extract EACH of bookmarks value from the doc, and I think “for loop” should do it. However, I failed.

Dim CurrentField as String
Dim result as string

result = “”

For i = 0 to (a.ActiveDocument.Bookmarks.Count) - 1
CurrentField = w.Bookmarks.Item(i) -> Run-time error ‘5941’
-> The requested member of collection does not exit
result = result ^ w.Bookmarks(CurrentField).Range.Text ^ chr(13)

Next i

How to define “collection” for this case?

Your help is greatly appreciated.

Extract Images In Word Document
Hi all,
i need to extract images stored in word document
it will be appreciatable if someone gives idea or code snippet
i used inlineshapes collection but not find solution


Script Extract Embedded Files From Word
I have some Word 2003 docs that have many embedded Outlook 2003 .msg file objects, I want all those .msg files out and in a folder on my file system, if I try and click and drag them out I get a scrap error message, either way, I would rather do so with VBA for Office but I don't know how, there are many .msg files in the word doc (approx 50), will someone please let me know if this can be done with Office VBA

Macro Word To Extract Words According To Dictionary
Hi, I need a macro word to extract words from a text in distinct languages. Looking at google, I found this code, but it doesn´t work with great texts (more than 1000 words).

Now, the code, open another document in which it copy the words that appear in the ms word dictionary. I thought that the solution can be to avoid this second document, and only remove the non dictionary words from the original doc.

Please take a look to the code, and tell me if you can help me! Thanks a lot!

Sub Macro1()
' ExtractNewWords Macro: Extracts words from your document
' that are not present in MS Word's spell-check dictionary
' Useful for terminology research
' Macro recorded on 14.08.02 by Tanya Harvey
' If no Word document is open
On Error GoTo MainStop
If Documents.Count = 0 Then
WordBasic.MsgBox "Open the document from which you wish to extract the words that are not present in MS Word's spell-check dictionary!"
Exit Sub
End If
' If more than one Word document is open
If Documents.Count > 1 Then
WordBasic.MsgBox "Close all Word documents and open only the document from which you wish to extract the words that are not present in MS Word's spell-check dictionary!"
Exit Sub
End If
' Declaration in confirmation dialogue box
Dim Prompt As String
Dim Title As String
Dim Response As String
Dim Style As Integer
Dim lingo As String
lingo = ActiveDocument.AttachedTemplate.LanguageID
For Each la In Languages
x = Application.Languages(la).ID
If x = lingo Then
lingo = la.NameLocal
End If
Next la
Prompt = "Is the language of your document <" + lingo$ + ">?" + Chr(13) + "(If not, click <No> and set the correct language!)" + Chr(13) + "" + Chr(13) + "This operation may take a while..."
Style = 36
Title = "Document language setting"
Response = MsgBox(Prompt, Style, Title)
If Response = vbNo Then
MsgBox "To set the language of your document, select:" + Chr(13) + "" + Chr(13) + "Edit/Select All" + Chr(13) + "Tools/Language/Set Language (select your language)" + Chr(13) + "Default/Yes/OK"
Exit Sub
' Open a new document in which to save the words
Set doct = Documents.Add
' Arrange open windows
' Activate the document from which to extract the terminology
Dim AnzahlFenster As Integer
Dim NummerAktivesFenster As Integer
AnzahlFenster = Application.Windows.Count
NummerAktivesFenster = Application.ActiveWindow.Index
If AnzahlFenster > NummerAktivesFenster Then
End If
' Select the entire content of the document
' For each word in the document do all instructions up to "Next"
For Each mot In Selection.Words
' If the word is not present in MS Word's spell-check dictionary
If mot.GetSpellingSuggestions.SpellingErrorType = wdSpellingInDictionary Then
' Activate the document listing the words extracted
' Remove any additional spaces after the word
mot = Trim(mot)
' Type the word in the list…
Selection.TypeText mot
' … followed by a paragraph mark
End If
WordBasic.MsgBox "End of spell check: All the words not present in MS Word's spell-check dictionary have been written to a separate file. Duplicates have been removed."
End If
If Err.Number <> 0 Then
MsgBox "An error has occurred. Make sure that the dictionary for the language of your document is installed (search your hard drive for <*.lex> to locate the dictionary files.)"
End If
End Sub

Extract Data Grid To Word Document
I am working on a Visual Basic project. Right now, I'm working on a query builder. Once the criteria is set and the query is ran, the data will show up in a data grid. I was wondering how I can extract this data (from the data grid) to a Word document.

Using VBA To Extract Dates From Multiple Word Files To Rename Them?
Application: Word 2002
Code: VBA
Problem: I need the ability in VBA to extract the date multiple files were either created or last modified so i can then prefix the existing file with the date.

file.doc > 20070416-file.doc
file2.doc > 20070416-file2.doc
file3.doc > 20070411-file3.doc

I have found some code to read a directories list of files into a list box, and now i need the ability to be able to read the created / last modifed date in a similar way.

Here is the code to read the contents to a list box:

Dim MyFile As String
Dim Counter As Long

'Create a dynamic array variable, and then declare its initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)

Dim DirectoryListArray1() As String
ReDim DirectoryListArray1(1000)
'Loop through all the files in the directory by using Dir$ function
MyFile = Dir$("c: est*.*")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile

MyFile = Dir$

Counter = Counter + 1

'Reset the size of the array without losing its values by using Redim Preserve
'ReDim Preserve DirectoryListArray(Counter - 1)

'To prove it worked you could run the following:

For Counter = 0 To UBound(DirectoryListArray)
'Debug.Print writes the results to the Immediate window (press Ctrl + G to view it)'
Debug.Print DirectoryListArray(Counter)
Next Counter

'To populate a Listbox from the array you could use:

ListBox1.List = DirectoryListArray

Any ideas?

Thanks in advance

Read Data Of Word Table And Save It Access Table
How i can read data of table in the word and save it in another table in access.

How To Extract Text Or Group Of Text From A Source
for example I have the following data in my variable....

a = "This is a Test text to extract by the program"

then I want to get the character from Test to by is there a faster way with out using the len, mid, left function of vb.

Like php regular expresions...

Word 97: How To Insert A Table Into An Existing Table Cell
Does anyone know how I can insert a New Table into a cell of another table?

In Word 2000, I can issue the following code when I am within a cell of a table and the table gets inserted correctly:

Dim rRange As Range, myTable As Table
With Selection
    Set rRange = .Range
    Set myTable = rRange.Tables.Add(Range:=.Range, NumRows:=2, NumColumns:=4)
End With

However, in Word97, I am not able to do this. I get an error telling me that a table already exists. Has anyone had any success with being able to insert a new table into a cell of an existing table without doing a lot of cell/row inserts and cell merges?

How To Insert Table Into A Cell Of Another Table Using Word Object
hi friends,

i have inserted a table into word do using word object through VB

wddoc.tables.add selection.range, 2, 4

now i wanto to insert a table into the cell of the table created.

can u help me how to do that

i have tried like this

wddoc.tables(1).cell(1,1).range.tables.add selection.range,2,4

but i am getting an error saying that table already exists in that location,



How To Insert Table Into A Table Cell Of Word
hi friends,

i am creating a word doc from VB and then i want to insert tables into it. i am inserting table in the following manner

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

but it is able to create the first table but not the second table. it is giving a error message saying that table already present in the location.

can u tell me how to insert 2 or more tables into the word doc through coding


How To Insert Table Into A Table Cell Of Word
hi friends

i want to add a table inside a table cell, i am using the following code to achieve this, but i am getting and error saying that the table is already located in the location. i think there is some problem with the range.

wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range.Tables.Add wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range, 2, 1


How To Insert Table Into A Table Cell Of Word
hi friends

i want to add a table inside a table cell, i am using the following code to achieve this, but i am getting and error saying that the table is already located in the location. i think there is some problem with the range.

set drange=wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range
wdapp.ActiveDocument.Tables(2).Cell(2, 1).Range.Tables.Add drange, 2, 1

i am using word 8.0 dll i.e word 97

Good Friend...

Convert HTML Table Into Word Table

I have a string in VB6 that is something like :
str = "<table> <tr> <td>r1c1</td> <td>r1c2</td> </tr> <tr>
<td>r2c1</td> <td>r2c2</td> </tr> </table>"

Is there a way I can convert this string into a table in word using VB 6 ?


Extract Text
A single cell contains city and date. vb: etten-Leur, 29 januari 2004
I want to extract/delete the city name (etten-leur), i want to keep the date as a string.

thnx in advance.


Extract Text From Txt

I am tryng to extract lines from a text file to a buffer, where the text lines should be analysed to look for server names inside the text.

I try to make a Loop extracting the line, looking for these contents and so on, but I haven,t yet accesed the file.

Could you help me?

Thank you!

the code:


Dim strFileName As String 'String of file to open
Dim strText As String 'Contents of file
Dim strFilter As String 'Common Dialog filter string
Dim strBuffer As String 'String buffer variable
Dim FileHandle% 'Variable to hold file handle

strFileName = "login_History.txt"
'Get a free file handle and assign it to the file handle variable
FileHandle% = FreeFile

'Open the file
Open strFileName For Input As #FileHandle%
Seek #FileHandle%, 2 ' Position festlegen.

'Make the mouse cursor an hourglass
MousePointer = vbHourglass

'Traverse the lines of the file
Do While Not EOF(FileHandle%) ' Check for end of file.

'Read a line of the file
Line Input #FileHandle%, strBuffer ' Read line of data.
strText = strBuffer ' Write the variable to analyze
' HEre must the code to seek for this server names


'Change the mousepointer back to the arrow
MousePointer = vbDefault

'Close the file once you have had your way with it
Close #FileHandle%

'Put the file name in the form caption

End Sub

Extract Text From Textbox
text box 1 = "random data here (30%)"

i need to extract the data inside the ( ). so remove all the data apart from the number.

cant be done with replace as the data will change all the time

To Extract Screen Text....Need Help
I have basic knowledge of VB and and I need help to do something complicated here:

My company had ported a legacy dos application into a full win32 program while retaining the same look and feel (80 by 25).

I am trying to develop some VB programs that could extract the text from this app (there is no copy function available at all) for other use. How could I go about doing it to intercept the text that are being displayed on screen? I read something about subclassing or window message, but have no clue on how to proceed.

Any pointer is highly appreciated

Copyright © 2005-08, All rights reserved