LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy/Paste Multiple cells from Excel to Word

Hello,
I'm new at VBA and have been polking around looking for some answers but
haven't found them yet. The code I'm using is listed below. Basically what
I want to do is copy cell B2 into word as a heading 1, cell C2 as a heading 2,
D2 as heading 3, and G2 as body text. I figured I would need to have two
macros, one to bring the text into word from excel and one to change the
style of the text to the correct heading/body text arrangement.

The problem I'm having with the code from excel that I'm using is that it is
pasting over what was previously brought it so i'm only left with the the
text for D2 and nothing else. I tried to make it add a paragraph at the end
of each so that it wouldn't overwrite it, but what's happening is the text is
being selected and pasted over each time. I don't know really anything about
VBA so anything I try is like a stab in the darkness. In order to get the
code to copy and past all 4 cells in a row i repeated the following code
which is opening the word doc and i think that's where the problem is. I
just don't know how to fix it:

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set wdApp = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open(fNameAndPath)
wdApp.Visible = True

I don't know if i'm going to need to use bookmarks to keep this from
happening, or if there is another way. Also, I need a solution that would
work with a loop, because i will need to loop this code until the frist blank
row.

Laura

The code:

Dim wdApp As Object
Dim wdDoc As Object
Dim fNameAndPath As String


fNameAndPath = "C:\data\Test.doc"

ActiveSheet.Range("B2:B2").Copy

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Set wdApp = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open(fNameAndPath)
wdApp.Visible = True

With wdDoc.Content
.Font.Name = "Tahoma"
.Font.Size = 20
.PasteSpecial DataType:=wdPasteText
End With

ActiveDocument.Content.InsertParagraphAfter

Workbooks("test.xls").Activate
ActiveSheet.Range("C2:C2").Copy

AppActivate "Microsoft Word"

With wdDoc.Content
.Font.Name = "Tahoma"
.Font.Size = 18
.PasteSpecial DataType:=wdPasteText
End With

ActiveDocument.Content.InsertParagraphAfter

Workbooks("test.xls").Activate
ActiveSheet.Range("D2:D2").Copy

AppActivate "Microsoft Word"

With wdDoc.Content
.Font.Name = "Tahoma"
.Font.Size = 16
.PasteSpecial DataType:=wdPasteText
End With

ActiveDocument.Content.InsertParagraphAfter

Workbooks("test.xls").Activate
ActiveSheet.Range("G2:G2").Copy

AppActivate "Microsoft Word"

With wdDoc.Content
.Font.Name = "Tahoma"
.Font.Size = 14
.PasteSpecial DataType:=wdPasteText
End With

ActiveDocument.Content.InsertParagraphAfter

End Sub

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200802/1

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy and paste (special) a series of cells into word raphiel2063 Excel Programming 0 September 10th 07 04:52 PM
How do I copy data in Excel cells and paste in Word w/o cell borde Nsimm13 Excel Discussion (Misc queries) 1 September 1st 06 03:35 PM
How to copy cells excel data and paste them under MS Word bookmark Bon Excel Programming 0 January 17th 06 03:36 PM
How do I copy selected cells in excel and paste into word table REVA Excel Programming 2 January 4th 06 09:43 PM
copy multiple worksheets of a workbook, and paste onto a Word document ( either create new doc file or paste onto an existing file.) I need this done by VBA, Excel Macro Steven Excel Programming 1 October 17th 05 08:56 AM


All times are GMT +1. The time now is 08:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"