Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

export word tables to excel

5 views
Skip to first unread message

Eckard Buchner

unread,
Jan 30, 2004, 1:47:34 AM1/30/04
to
this question must have been asked here before...

I'd like to write a makro that exports word 97 tables into excel 97. Copying
and pasting them is not a solution for me, because I would have to export
the tables regularly. I have not much experience in macro writing, could
someone give me a hint...

Thanks
Eckard


macropod

unread,
Jan 30, 2004, 5:11:50 AM1/30/04
to
Hello Eckard,

A macro would probably do no more than the copy & paste you're doing now. If
you need the data in Excel, it would probably be better to start off with it
in Excel in the first place - it's fairly easy to link part or all of an
Excel spreadsheet to a Word document.

Cheers


"Eckard Buchner" <e...@web.de> wrote in message
news:bvcum7$r3sn8$1...@ID-24152.news.uni-berlin.de...


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.561 / Virus Database: 353 - Release Date: 13/01/2004


Eckard Buchner

unread,
Feb 2, 2004, 2:06:58 AM2/2/04
to
That is a good idea. But I have word documents already that contain word
tables. I really would like to have a macro for that. How can I "load" a
word document in an excel macro? The word object model should contain the
table objects
Thanks
Eckard

"macropod" <pNeOd.s...@pcug.org.au (del NO.SPAM)> schrieb im
Newsbeitrag news:bvdal1$qksdd$1...@ID-216222.news.uni-berlin.de...

macropod

unread,
Feb 2, 2004, 5:32:26 AM2/2/04
to
Hi Eckard,

The following code (for running from Excel) should get you going. It uses
early binding, so requires a reference to be set up in advance to the Word #
Object Library (In the VBE, Tools|References, then scroll down till you find
it).

Sub openWordDoc()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Open(Filename:="D:\Work\Contacts.doc")
wdApp.Visible = True
'Call or insert your table copying code here
wdApp.ActiveDocument.Save
wdApp.ActiveDocument.Close
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub

Cheers

"Eckard Buchner" <e...@web.de> wrote in message

news:bvksuq$spe8h$1...@ID-24152.news.uni-berlin.de...

Eckard Buchner

unread,
Feb 3, 2004, 2:30:19 AM2/3/04
to
Great, thank you for your help! I've got a macro now, and it is working
fine.

Is there a way to keep Word from asking "save changes?" before it quits?
Something I'm doing in my macro (see below) seems to change the document

Thanks
Eckard

' ------------------------------
Sub ImportDoc()


Dim wdApp As Word.Application
Dim wdDoc As Word.Document

Dim wdTable As Word.Table
Dim wdRow As Word.Row
Dim wdCell As Word.Cell
Dim nRow, nCol, nTab
Dim bHeader As Boolean

Set wdApp = New Word.Application
Set wdDoc =

wdApp.Documents.Open(FileName:="K:\Projekte\SironWeb\TDI-Integration\SironWe
b Integration TDI.doc")


wdApp.Visible = True
'Call or insert your table copying code here

Range("A1:E999").Clear

nTab = 1
nRow = 1

For Each wdTable In wdDoc.tables

nTab = nTab + 1
bHeader = True

For Each wdRow In wdTable.rows
nCol = 1
nRow = nRow + 1
For Each wdCell In wdRow.cells
nCol = nCol + 1

With ActiveSheet.cells(nRow, nCol)
.Select
.Font.Bold = bHeader
If bHeader Then
.HorizontalAlignment = xlCenter
Else
.HorizontalAlignment = xlHAlignGeneral
End If
End With

wdCell.Range.Copy
ActiveSheet.Paste

Next
bHeader = False
Next
nRow = nRow + 1
Next


'wdApp.ActiveDocument.Save


'wdApp.ActiveDocument.Close
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub

"macropod" <pNeOd.s...@pcug.org.au (del NO.SPAM)> schrieb im
Newsbeitrag news:bvl8v7$tcfam$1...@ID-216222.news.uni-berlin.de...

macropod

unread,
Feb 3, 2004, 4:07:21 AM2/3/04
to
Hi Eckard,

You could save the document before closing, as per the code you've commented
out, or you could change that line to:
wdApp.ActiveDocument.Saved = True
Alternatively, you could use:
wdApp.ActiveDocument.Application.DisplayAlerts = False
at the same point
Cheers


"Eckard Buchner" <e...@web.de> wrote in message

news:bvnime$uhsf5$1...@ID-24152.news.uni-berlin.de...

Ruby Tuesday

unread,
Feb 21, 2004, 2:41:07 AM2/21/04
to
Will this script work for Word/Excel XP or Word/Excel 2003?

Thanks

"Eckard Buchner" <e...@web.de> wrote in message

news:bvnime$uhsf5$1...@ID-24152.news.uni-berlin.de...

0 new messages