Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Trefor
 
Posts: n/a
Default in an excel macro can you import data from word into a cell?

I have several word documents being emailed to me containing tables. I would
like to be able to import some of the data in the word table into a cell in
my spreadsheet. Is this possible using a macro in the spreadsheet?

--
Trefor
  #2   Report Post  
HiArt
 
Posts: n/a
Default


hi Trefor,

Yes, that's one of the advantages of the MS Office Family!

Look in Excel VBA help "Controlling One Microsoft Office Application
from Another".

A quick search in Google found this:
http://www.mindspring.com/~tflynn/ex...html#Open_Word.

You'd replace the "With mywdRange" with code appropraite to your
problem. It's fairly straight-forward if you know Word VBA. Once word
is open use:

Selection.Tables(1).Select ' goes to a specified table occurence
Selection.SelectRow
Selection.Copy

The switch back to Excel and Paste.

HTH

Art


--
HiArt
------------------------------------------------------------------------
HiArt's Profile: http://www.excelforum.com/member.php...o&userid=19953
View this thread: http://www.excelforum.com/showthread...hreadid=472033

  #3   Report Post  
Trefor
 
Posts: n/a
Default

Thankyou for the reply, but I must be missing something here. I am still
learning about macros/VBA in Excel and no nothing about macros/VBA in Word.

I tried to run the code and got an error:

Dim wdApp As Word.Application User-defined type not defined.

--
Trefor


"HiArt" wrote:


hi Trefor,

Yes, that's one of the advantages of the MS Office Family!

Look in Excel VBA help "Controlling One Microsoft Office Application
from Another".

A quick search in Google found this:
http://www.mindspring.com/~tflynn/ex...html#Open_Word.

You'd replace the "With mywdRange" with code appropraite to your
problem. It's fairly straight-forward if you know Word VBA. Once word
is open use:

Selection.Tables(1).Select ' goes to a specified table occurence
Selection.SelectRow
Selection.Copy

The switch back to Excel and Paste.

HTH

Art


--
HiArt
------------------------------------------------------------------------
HiArt's Profile: http://www.excelforum.com/member.php...o&userid=19953
View this thread: http://www.excelforum.com/showthread...hreadid=472033


  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Click on Tools|References
Then scroll down looking for:
Microsoft Word xx.0 Object library

(xx.0 will change with the version of word/office you have.)

Trefor wrote:

Thankyou for the reply, but I must be missing something here. I am still
learning about macros/VBA in Excel and no nothing about macros/VBA in Word.

I tried to run the code and got an error:

Dim wdApp As Word.Application User-defined type not defined.

--
Trefor

"HiArt" wrote:


hi Trefor,

Yes, that's one of the advantages of the MS Office Family!

Look in Excel VBA help "Controlling One Microsoft Office Application
from Another".

A quick search in Google found this:
http://www.mindspring.com/~tflynn/ex...html#Open_Word.

You'd replace the "With mywdRange" with code appropraite to your
problem. It's fairly straight-forward if you know Word VBA. Once word
is open use:

Selection.Tables(1).Select ' goes to a specified table occurence
Selection.SelectRow
Selection.Copy

The switch back to Excel and Paste.

HTH

Art


--
HiArt
------------------------------------------------------------------------
HiArt's Profile: http://www.excelforum.com/member.php...o&userid=19953
View this thread: http://www.excelforum.com/showthread...hreadid=472033



--

Dave Peterson
  #5   Report Post  
Trefor
 
Posts: n/a
Default

Dave, thankyou that fixed that problem, but the bigger issue I am still
having problems with. I have searched around here and found many people
looking for the same thing (using keywords: grab, copy, import, extract)

To explain what I am trying to do in more detail: (using Office 2003)

I would like to run a macro in Excel that:

1. Checks to see if there is an open Word document. (I dont want to specify
a name or have to open the file from within Excel)

2. Select and copy the data from word to excel. (The word documents (for
some reason beyond my control) have text boxes set in autoshapes to look like
tables, each cell within the €śtable€ť has a text box and the text box has
several lines of text in it (names and addresses for example))

3. I am guessing for simplicity it would be easier to just grab everything,
then paste it into a "scratch" area in excel, and then I can pick and choose
what I want from the scratch area.

I am fairly happy with macro's/VBA in excel, what I am not familiar with is
VBA in Word or switching between the two.

Any help very much appreciated.

--
Trefor


"Dave Peterson" wrote:

Click on Tools|References
Then scroll down looking for:
Microsoft Word xx.0 Object library

(xx.0 will change with the version of word/office you have.)

Trefor wrote:

Thankyou for the reply, but I must be missing something here. I am still
learning about macros/VBA in Excel and no nothing about macros/VBA in Word.

I tried to run the code and got an error:

Dim wdApp As Word.Application User-defined type not defined.

--
Trefor

"HiArt" wrote:


hi Trefor,

Yes, that's one of the advantages of the MS Office Family!

Look in Excel VBA help "Controlling One Microsoft Office Application
from Another".

A quick search in Google found this:
http://www.mindspring.com/~tflynn/ex...html#Open_Word.

You'd replace the "With mywdRange" with code appropraite to your
problem. It's fairly straight-forward if you know Word VBA. Once word
is open use:

Selection.Tables(1).Select ' goes to a specified table occurence
Selection.SelectRow
Selection.Copy

The switch back to Excel and Paste.

HTH

Art


--
HiArt
------------------------------------------------------------------------
HiArt's Profile: http://www.excelforum.com/member.php...o&userid=19953
View this thread: http://www.excelforum.com/showthread...hreadid=472033



--

Dave Peterson



  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default

This will check to see if MSWord is running and check to see if there's an
active document in word:

Option Explicit
Sub testme01()

Dim WDApp As Object
Dim WDDoc As Object

Set WDApp = Nothing
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
MsgBox "Word isn't running!"
Exit Sub
End If

WDApp.Visible = True 'at least for testing, just to make sure

Set WDDoc = Nothing
On Error Resume Next
Set WDDoc = WDApp.activedocument
On Error GoTo 0

If WDDoc Is Nothing Then
MsgBox "No activedocument in Word"
Exit Sub
End If

End Sub

When I need to do stuff in word, I usually record a macro when I do it
manually. Then I struggle to make it work the way I want.

If you do that and still have trouble, you can post back--or post to an MSWord
newsgroup.



Trefor wrote:

Dave, thankyou that fixed that problem, but the bigger issue I am still
having problems with. I have searched around here and found many people
looking for the same thing (using keywords: grab, copy, import, extract)

To explain what I am trying to do in more detail: (using Office 2003)

I would like to run a macro in Excel that:

1. Checks to see if there is an open Word document. (I dont want to specify
a name or have to open the file from within Excel)

2. Select and copy the data from word to excel. (The word documents (for
some reason beyond my control) have text boxes set in autoshapes to look like
tables, each cell within the €śtable€ť has a text box and the text box has
several lines of text in it (names and addresses for example))

3. I am guessing for simplicity it would be easier to just grab everything,
then paste it into a "scratch" area in excel, and then I can pick and choose
what I want from the scratch area.

I am fairly happy with macro's/VBA in excel, what I am not familiar with is
VBA in Word or switching between the two.

Any help very much appreciated.

--
Trefor

"Dave Peterson" wrote:

Click on Tools|References
Then scroll down looking for:
Microsoft Word xx.0 Object library

(xx.0 will change with the version of word/office you have.)

Trefor wrote:

Thankyou for the reply, but I must be missing something here. I am still
learning about macros/VBA in Excel and no nothing about macros/VBA in Word.

I tried to run the code and got an error:

Dim wdApp As Word.Application User-defined type not defined.

--
Trefor

"HiArt" wrote:


hi Trefor,

Yes, that's one of the advantages of the MS Office Family!

Look in Excel VBA help "Controlling One Microsoft Office Application
from Another".

A quick search in Google found this:
http://www.mindspring.com/~tflynn/ex...html#Open_Word.

You'd replace the "With mywdRange" with code appropraite to your
problem. It's fairly straight-forward if you know Word VBA. Once word
is open use:

Selection.Tables(1).Select ' goes to a specified table occurence
Selection.SelectRow
Selection.Copy

The switch back to Excel and Paste.

HTH

Art


--
HiArt
------------------------------------------------------------------------
HiArt's Profile: http://www.excelforum.com/member.php...o&userid=19953
View this thread: http://www.excelforum.com/showthread...hreadid=472033



--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I import formmail data to a custom excel template? cxlough41 Excel Worksheet Functions 1 July 1st 05 12:59 AM
Excel data not transfering to Word. Colums are expanded. carolsue1313 New Users to Excel 2 June 24th 05 08:16 PM
Macro - Open Word with Excel macro Bill Excel Discussion (Misc queries) 3 May 23rd 05 11:21 PM
exporting excel worksheet to word morrowkd Links and Linking in Excel 1 May 11th 05 11:23 PM
Can Excel Export Data to Word Format? Reddiance Excel Discussion (Misc queries) 2 April 18th 05 06:03 PM


All times are GMT +1. The time now is 05:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"