Adding empty row to word from excel

Cello

New Member
Joined
Jan 7, 2005
Messages
17
Hi, I hope someone could answer this simple question. I´m trying to paste text to word from excel cells. It works fine except for one small (but significant) factor. The word paragraphs should be separated by one empty line (or paragraph). I cannot do this. The paragraphs follow each other no matter what. That is, they are separata paragraphs but without that empty line between them.

Here´s the code. What should I add in order to get an empty line or paragraph to separate pasted paragraphs?

--------

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

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

Set DocWD = AppWD.Documents.Add
With DocWD
Set RangeWD = .Range
Sheets("T").Select
Range("A15").Select
Selection.Copy
With RangeWD
.PasteSpecial
Sheets("T").Select
Range("A17").Select
Selection.Copy
With RangeWD
.PasteSpecial
End With
End With

End With

End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Bruno

Active Member
Joined
Feb 17, 2002
Messages
491
Hi Cello,

Add this line to add a extra -empty- paragraph :
Selection.TypeParagraph
 

Cello

New Member
Joined
Jan 7, 2005
Messages
17
Thanks for helping, but I guess that won´t work.

I´ve tried to add this line there

AppWD.Selection.Paragraphs(1).Range.InsertParagraphBefore

and even this line instead of that

AppWD.Selection.Paragraphs(1).Range.InsertParagraphAfter

Now, since there are two cells that are copied from Excel, the added paragraph should be placed between those paragraphs. The first line inserts it before both paragraphs, and the second line after both paragraphs.

I can´t place it where it belongs, between the paragraphs. Any ideas?
 

Cello

New Member
Joined
Jan 7, 2005
Messages
17
And to be exact, I´ve added those two lines after these

Range("A17").Select
Selection.Copy
 

Bruno

Active Member
Joined
Feb 17, 2002
Messages
491

ADVERTISEMENT

Code:
...
Range("A15").Select
Selection.Copy
With RangeWD
.PasteSpecial

'add this line
AppWD.Selection.Paragraphs(1).Range.InsertParagraphAfter

Sheets("T").Select
Range("A17").Select
Selection.Copy
...
 

Cello

New Member
Joined
Jan 7, 2005
Messages
17
Hi, still same result. The added paragraph goes either on line 1 (insertparagraphbefore) or after the two paragraphs (insertparagraphafter), but not between them.

This is driving me crazy.
 

Bruno

Active Member
Joined
Feb 17, 2002
Messages
491

ADVERTISEMENT

Strange, the code works fine for me...

You've put the extra code after the first .PasteSpecial and before the second .PasteSpecial ?
 

Cello

New Member
Joined
Jan 7, 2005
Messages
17
Hmm...this is strange.

Your result in Word looks like this?

---------
This is the first line (Range A15) from excel.

This is the second line (Range A17) from excel.
---------

My code gives this result:

---------
This is the first line (Range A15) from excel.
This is the second line (Range A17) from excel.
---------

It lacks the empty row.
 

Cello

New Member
Joined
Jan 7, 2005
Messages
17
And yes, thats where I put it, between the first Pastespecial and the second Pastespecial.
 

Bruno

Active Member
Joined
Feb 17, 2002
Messages
491
Ok now I see the difference
Try this code
Code:
...
Set AppWD = CreateObject("Word.Application")
With AppWD
    .Visible = True
    .Documents.Add
    .Selection.Paragraphs(1).Range.InsertAfter _
        Sheets("T").Range("A15").Value
    .ActiveDocument.Content.InsertAfter _
        Sheets("T").Range("A17").Value
    .Selection.Paragraphs(1).Range.InsertAfter Chr$(13)
End With
...
 

Forum statistics

Threads
1,147,674
Messages
5,742,541
Members
423,736
Latest member
dracula cyrus

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top