PC Review


Reply
Thread Tools Rate Thread

Copy/Paste Excel Cell Range to Word Bookmark

 
 
=?Utf-8?B?RGFuIFRob3JtYW4=?=
Guest
Posts: n/a
 
      30th Jan 2007
Hi all.

I am basically looking use my macro to copy a range of cells in excel and
paste them to a bookmarked spot in a word document that my macro opens. I
would like to retain the formatting of the range of cells (so that i am,
effectively, pasting a formatted table into word). I cannot seem to figure
out how to do this, however.

I am using Office 2k3
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFydGluIEZpc2hsb2Nr?=
Guest
Posts: n/a
 
      31st Jan 2007
I would try the word groups, as they have much more expertise in that field.

But why not try the macro recorder and so how far you get.
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Dan Thorman" wrote:

> Hi all.
>
> I am basically looking use my macro to copy a range of cells in excel and
> paste them to a bookmarked spot in a word document that my macro opens. I
> would like to retain the formatting of the range of cells (so that i am,
> effectively, pasting a formatted table into word). I cannot seem to figure
> out how to do this, however.
>
> I am using Office 2k3

 
Reply With Quote
 
macropod
Guest
Posts: n/a
 
      31st Jan 2007
Hi Dan,

Here's some code to get you started:

Sub SendRangeToDoc()
Dim wdApp As Word.Application
Dim WdDoc As String
'Copy range
ActiveWorkbook.Sheets(1).Range("A1:J10").Copy
'Establish link to Word
WdDoc = "C:\My Documents\MyFile.doc"
If Dir(WdDoc) <> "" Then
Set wdApp = New Word.Application
wdApp.Visible = True
With wdApp
'open the Word Document
Documents.Open Filename:=WdDoc
With wdApp
Dim BmkNm As String
BmkNm = "xlTbl"
With ActiveDocument
If .Bookmarks.Exists(BmkNm) Then
.Bookmarks(BmkNm).Range.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, _
Placement:=wdInLine, DisplayAsIcon:=False
.Save
Else
MsgBox "Bookmark: " & BmkNm & " not found."
End If
End With
End With
End With
Else
MsgBox "File: " & WdDoc & " not found."
End If
'Release Word object
Set wdApp = Nothing
End Sub

However, depending on what you're trying to achieve, you may not need a macro at all. Word is quite capable of linking to a
specified range in an Excel workbook, via a LINK field. With this, the embedded object in Word will update to reflect the current
data in Excel. If your data range in Excel is named, and you use that name in the LINK field, then changing the range the name
applies to in Excel will cause Word to display the new range.

Cheers

--
macropod
[MVP - Microsoft Word]


"Dan Thorman" <(E-Mail Removed)> wrote in message news:44A723E9-ADC7-4BF5-ACD4-(E-Mail Removed)...
| Hi all.
|
| I am basically looking use my macro to copy a range of cells in excel and
| paste them to a bookmarked spot in a word document that my macro opens. I
| would like to retain the formatting of the range of cells (so that i am,
| effectively, pasting a formatted table into word). I cannot seem to figure
| out how to do this, however.
|
| I am using Office 2k3


 
Reply With Quote
 
=?Utf-8?B?RGFuIFRob3JtYW4=?=
Guest
Posts: n/a
 
      31st Jan 2007
Thanks!!! This line was exactly what i needed:

With ActiveDocument
If .Bookmarks.Exists(BmkNm) Then
..Bookmarks(BmkNm).Range.PasteSpecial Link:=False,
DataType:=wdPasteOLEObject, _
Placement:=wdInLine, DisplayAsIcon:=False

"macropod" wrote:

> Hi Dan,
>
> Here's some code to get you started:
>
> Sub SendRangeToDoc()
> Dim wdApp As Word.Application
> Dim WdDoc As String
> 'Copy range
> ActiveWorkbook.Sheets(1).Range("A1:J10").Copy
> 'Establish link to Word
> WdDoc = "C:\My Documents\MyFile.doc"
> If Dir(WdDoc) <> "" Then
> Set wdApp = New Word.Application
> wdApp.Visible = True
> With wdApp
> 'open the Word Document
> Documents.Open Filename:=WdDoc
> With wdApp
> Dim BmkNm As String
> BmkNm = "xlTbl"
> With ActiveDocument
> If .Bookmarks.Exists(BmkNm) Then
> .Bookmarks(BmkNm).Range.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, _
> Placement:=wdInLine, DisplayAsIcon:=False
> .Save
> Else
> MsgBox "Bookmark: " & BmkNm & " not found."
> End If
> End With
> End With
> End With
> Else
> MsgBox "File: " & WdDoc & " not found."
> End If
> 'Release Word object
> Set wdApp = Nothing
> End Sub
>
> However, depending on what you're trying to achieve, you may not need a macro at all. Word is quite capable of linking to a
> specified range in an Excel workbook, via a LINK field. With this, the embedded object in Word will update to reflect the current
> data in Excel. If your data range in Excel is named, and you use that name in the LINK field, then changing the range the name
> applies to in Excel will cause Word to display the new range.
>
> Cheers
>
> --
> macropod
> [MVP - Microsoft Word]
>
>
> "Dan Thorman" <(E-Mail Removed)> wrote in message news:44A723E9-ADC7-4BF5-ACD4-(E-Mail Removed)...
> | Hi all.
> |
> | I am basically looking use my macro to copy a range of cells in excel and
> | paste them to a bookmarked spot in a word document that my macro opens. I
> | would like to retain the formatting of the range of cells (so that i am,
> | effectively, pasting a formatted table into word). I cannot seem to figure
> | out how to do this, however.
> |
> | I am using Office 2k3
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy excel text on a range and paste special to Word =?Utf-8?B?RGFuaWVs?= Microsoft Excel Programming 5 31st Mar 2008 06:52 PM
copy/paste from excel to word including cell color robr Microsoft Excel Misc 0 12th Sep 2007 03:41 PM
How can I copy and paste from word to excel, w/o being in one cell =?Utf-8?B?am9zdGVy?= Microsoft Excel Misc 0 22nd Jun 2007 09:13 PM
How do I copy data in Excel cells and paste in Word w/o cell borde =?Utf-8?B?TnNpbW0xMw==?= Microsoft Excel Misc 1 1st Sep 2006 03:35 PM
How to copy cells excel data and paste them under MS Word bookmark Bon Microsoft Excel Programming 0 17th Jan 2006 03:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:36 AM.