ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Pasting text from Excel to Word (macro) (https://www.excelbanter.com/excel-programming/321499-pasting-text-excel-word-macro.html)

TT[_2_]

Pasting text from Excel to Word (macro)
 
I've asked before but nobody could then help me - maybe this time I get
lucky. :)

I'm trying to paste text from Excel to Word. I cannot get it to work
right - everything is pasted on line 1 in Word. The previously pasted text
gets replaces by the later pasted text. The later text should of course be
pasted on line 2 etc. Can anyone help me out here?

Here's the macro I've been trying to use:

Sub TW()

Dim AppWD As Word.Application
Dim DocWD As Word.Document
Dim RangeWD As Word.Range

Set AppWD = CreateObject("Word.Application.11")
AppWD.Visible = True

Set DocWD = AppWD.Documents.Add
With DocWD
Set RangeWD = .Range
Sheets("T").Select
Range("A15").Select
Selection.Copy
With RangeWD
..Font.Name = "Arial"
..PasteSpecial DataType:=wdPasteText, Placement:=wdInLine
..InsertParagraphAfter
..Collapse wdCollapseEnd
..InsertParagraphAfter
End With
Set RangeWD = .Range
Sheets("T").Select
Range("A17").Select
Selection.Copy
With RangeWD
..Font.Name = "Arial"
..PasteSpecial DataType:=wdPasteText, Placement:=wdInLine
..InsertParagraphAfter
'.InsertParagraphAfter
..Collapse wdCollapseEnd
..InsertParagraphAfter
End With

End With

Sheets("S").Activate

End Sub




Dave Peterson[_5_]

Pasting text from Excel to Word (macro)
 
Maybe looking at how Debra Dalgleish advances to a new line in her code to paste
comments from excel to word would help:

http://www.contextures.com/xlcomments03.html#CopyToWord



TT wrote:

I've asked before but nobody could then help me - maybe this time I get
lucky. :)

I'm trying to paste text from Excel to Word. I cannot get it to work
right - everything is pasted on line 1 in Word. The previously pasted text
gets replaces by the later pasted text. The later text should of course be
pasted on line 2 etc. Can anyone help me out here?

Here's the macro I've been trying to use:

Sub TW()

Dim AppWD As Word.Application
Dim DocWD As Word.Document
Dim RangeWD As Word.Range

Set AppWD = CreateObject("Word.Application.11")
AppWD.Visible = True

Set DocWD = AppWD.Documents.Add
With DocWD
Set RangeWD = .Range
Sheets("T").Select
Range("A15").Select
Selection.Copy
With RangeWD
.Font.Name = "Arial"
.PasteSpecial DataType:=wdPasteText, Placement:=wdInLine
.InsertParagraphAfter
.Collapse wdCollapseEnd
.InsertParagraphAfter
End With
Set RangeWD = .Range
Sheets("T").Select
Range("A17").Select
Selection.Copy
With RangeWD
.Font.Name = "Arial"
.PasteSpecial DataType:=wdPasteText, Placement:=wdInLine
.InsertParagraphAfter
'.InsertParagraphAfter
.Collapse wdCollapseEnd
.InsertParagraphAfter
End With

End With

Sheets("S").Activate

End Sub


--

Dave Peterson


All times are GMT +1. The time now is 07:14 AM.

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