Macro to automate copying text from Word doc to Excel spreadsheet

B

Bev

I would like to automate the copying of text from Word to an Excel cell.
Each time, the text selection would be different from the previously selected
text, and the destination cell in Excel would also be different. The text
length is also variable. Ideally, the macro should contain the steps to copy
the highlighted text in the Word document, navigate to the open Excel
spreadsheet and paste the text into the cell that already has focus. By
pressing Enter, the focus is passed to the cell underneath. The macro should
then also record the step to navigate back to the Word document. That would
then be the end of the macro.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?QmV2?=,
I would like to automate the copying of text from Word to an Excel cell.
Each time, the text selection would be different from the previously selected
text, and the destination cell in Excel would also be different. The text
length is also variable. Ideally, the macro should contain the steps to copy
the highlighted text in the Word document, navigate to the open Excel
spreadsheet and paste the text into the cell that already has focus. By
pressing Enter, the focus is passed to the cell underneath. The macro should
then also record the step to navigate back to the Word document. That would
then be the end of the macro.
See if this does what you need

Sub CopySelectionToExcel()
Dim xlApp As Object

On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
If Err.Number = 429 Then
MsgBox "Excel is not running. The macro cannot continue"
Exit Sub
End If
On Error GoTo 0
Selection.Copy
xlApp.ActiveSheet.Paste
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top