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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi Cello,

Add this line to add a extra -empty- paragraph :
Selection.TypeParagraph
 
Upvote 0
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?
 
Upvote 0
And to be exact, I´ve added those two lines after these

Range("A17").Select
Selection.Copy
 
Upvote 0
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
...
 
Upvote 0
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.
 
Upvote 0
Strange, the code works fine for me...

You've put the extra code after the first .PasteSpecial and before the second .PasteSpecial ?
 
Upvote 0
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.
 
Upvote 0
And yes, thats where I put it, between the first Pastespecial and the second Pastespecial.
 
Upvote 0
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
...
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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
Back
Top