+ Reply to Thread
Results 1 to 3 of 3

Pasting text from Excel to Word (macro)

  1. #1
    TT
    Guest

    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




  2. #2
    Forum Contributor
    Join Date
    12-11-2004
    MS-Off Ver
    2007
    Posts
    137
    Hello

    you may try


    Sub TW()
    Dim AppWD As Word.Application
    Dim DocWD As Word.Document

    Set AppWD = CreateObject("Word.Application")
    AppWD.Visible = True
    Set DocWD = AppWD.Documents.Add

    With DocWD.Range
    .Font.Name = "Arial"
    .Text = Sheets("T").Range("A15")
    '************************************************
    .Collapse Direction:=wdCollapseEnd 'last line in the Word doc
    .InsertBreak wdLineBreak 'next line
    '************************************************
    .Font.Name = "Arial"
    .Text = Sheets("T").Range("A17")
    End With

    Sheets("S").Activate

    End Sub



    each Cell value is add on one line ( with no Copy/Paste )


    regards
    michel

  3. #3
    Dave Peterson
    Guest

    Re: 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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1