Paste non-adjacent cell content from Excel to open Word document

J

Jimbob

Hi

There are many posts here addressing this subject but my particular
requirement is to paste from Excel to an existing open Word template.
The Word filename will be variable. I will have the cursor positioned at the
insertion point in the Word template and want to Alt, Tab, select and paste
non-adjacent cells (known OFFSET is always 0, 11) from my Excel workbook and
paste as unformatted text into Word.

When I try this manually, I always get the intervening cell content as well
so I’m guessing 2 copy/paste events are needed.

BTW, I‘m using 2003.

Thanks in advance
 
D

Dave Peterson

I'd paste an intermediate copy into a new worksheet. Then copy|Paste from there
into MSWord.
 
J

Jimbob

Thanks for that Dave and it works a treat.
The question remains, how to switch to the open Word document. I need to
copy data repeatedly from selected elements of the workbook. It’s this
swapping which is the main stumbling block.
Regards
 
D

Dave Peterson

If you're controlling MSWord from excel, you can use something like:

Option Explicit
Sub testme()

'Dim WDApp As Word.Application
'Dim WDDoc As Word.Document
Dim WDApp As Object
Dim WDDoc As Object
Dim myDocName As String
Dim WordWasRunning As Boolean
Dim testStr As String

myDocName = "C:\my documents\word\doc10.doc"

testStr = ""
On Error Resume Next
testStr = Dir(myDocName)
On Error GoTo 0
If testStr = "" Then
MsgBox "Word file not found!"
Exit Sub
End If

WordWasRunning = True
On Error Resume Next
Set WDApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WDApp = CreateObject("Word.Application")
WordWasRunning = False
End If

WDApp.Visible = True 'at least for testing!

Set WDDoc = WDApp.documents.Open(Filename:=myDocName)

'your code do to the copy|paste to a new sheet.
'then your code to do the copy from that new sheet to MSWord.

'If WordWasRunning Then
' 'leave it running
'Else
' WDApp.Quit
'End If

Set WDDoc = Nothing
Set WDApp = Nothing

End Sub

You may want to add a bookmark in your word document where the data gets pasted,
then use that bookmark.

I don't automate MSWord enough to help you with that portion. If you don't get
a response here, I'd suggest asking in an MSWord newsgroup. Be sure to include
that you're automating MSWord from excel--and what version of MSOffice you're
using.
 

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