View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Paste non-adjacent cell content from Excel to open Word docume

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.

Jimbob wrote:

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. Its this
swapping which is the main stumbling block.
Regards


--

Dave Peterson