ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Paste non-adjacent cell content from Excel to open Word document (https://www.excelbanter.com/excel-programming/416640-paste-non-adjacent-cell-content-excel-open-word-document.html)

Jimbob

Paste non-adjacent cell content from Excel to open Word document
 
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 Im guessing 2 copy/paste events are needed.

BTW, I€˜m using 2003.

Thanks in advance


Dave Peterson

Paste non-adjacent cell content from Excel to open Word document
 
I'd paste an intermediate copy into a new worksheet. Then copy|Paste from there
into MSWord.

Jimbob wrote:

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 Im guessing 2 copy/paste events are needed.

BTW, I€˜m using 2003.

Thanks in advance


--

Dave Peterson

Jimbob

Paste non-adjacent cell content from Excel to open Word docume
 
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

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


All times are GMT +1. The time now is 12:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com