Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 02-21-2019, 03:23 PM
pfittro pfittro is offline Windows 10 Office 2019
Novice
 
Join Date: Feb 2019
Posts: 3
pfittro is on a distinguished road
Post Inserting a paragraph character using VBA

I would like to go through my word document one line at a time and at the end of each line there needs to be a paragraph character "^p". If there is not one I would like VBA to insert one.
Reply With Quote
  #2  
Old 02-21-2019, 05:38 PM
Guessed's Avatar
Guessed Guessed is online now Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,080
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

Really? Can you explain why you want to turn your wrapping paragraph text into discrete paragraphs?
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 02-21-2019, 08:23 PM
pfittro pfittro is offline Windows 10 Office 2019
Novice
 
Join Date: Feb 2019
Posts: 3
pfittro is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Really? Can you explain why you want to turn your wrapping paragraph text into discrete paragraphs?
I am needing to copy and paste my word document into excel while retaining the same format and spacing. Excel does not recognize wrapping paragraph text but does recognize discrete paragraphs.
Reply With Quote
  #4  
Old 02-21-2019, 09:00 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,098
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

You can't retain the Word formatting that way, though you could enable text wrapping within Excel. Moreover, a document that's got complex formatting (e.g. numbered, bulleted, indented, justified paragraphs) would be totally screwed up for copy/paste purposes by what you're suggesting. Perhaps you should consider pasting the document into Excel as an embedded object.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 02-26-2019, 12:45 PM
pfittro pfittro is offline Windows 10 Office 2019
Novice
 
Join Date: Feb 2019
Posts: 3
pfittro is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
You can't retain the Word formatting that way, though you could enable text wrapping within Excel. Moreover, a document that's got complex formatting (e.g. numbered, bulleted, indented, justified paragraphs) would be totally screwed up for copy/paste purposes by what you're suggesting. Perhaps you should consider pasting the document into Excel as an embedded object.
It will retain the same formatting using a discrete paragraph for each line. Inserting the word document as an embedded object does not populate any cells. Instead it is just a floating block.

The purpose of this is to use excel to quickly draw a table in Revit with notes formatted in Word. Unfortunately Autodesk has not made Revit friendly to bringing in large blocks of notes from Word.

If there is a simple code for my original post please let me know.
Reply With Quote
  #6  
Old 02-26-2019, 01:35 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,098
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Evidently, you haven't tried with using a Word document with numbered or bulleted paragraphs, paragraphs with first-line indents, justified text, etc., etc.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #7  
Old 02-26-2019, 01:53 PM
kilroy kilroy is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 62
kilroy is on a distinguished road
Default

If you're just looking to put each sentence on a single line this will work assuming each sentence ends with a period and then a space and no numbered or bulleted paragraphs like macropod pointed out. I know there's a way to include all punctuation you would normally see at the end of a sentence but I don't know it.

Code:
Sub FindReplaceX2()
Selection.WholeStory
With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = ". "
    .Replacement.Text = ".^p"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    Selection.Find.Execute Replace:=wdReplaceAll
End With
Selection.WholeStory
With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^13{2,}"
    .Replacement.Text = "^p"
    .Forward = True
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
End With
End Sub
Reply With Quote
  #8  
Old 02-26-2019, 02:05 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,098
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

That will give false results where abbreviations are used ...
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #9  
Old 02-26-2019, 02:20 PM
kilroy kilroy is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 62
kilroy is on a distinguished road
Default

Yes I thought about that after. - Dr. Mr. etc. Thanks
Reply With Quote
  #10  
Old 02-26-2019, 02:25 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,098
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Besides which, even if one were to break paragraphs into lines as the OP suggests, copying & pasting the result into Excel would cause each line to be put in successive cells, not in the same cell.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #11  
Old 02-26-2019, 02:33 PM
kilroy kilroy is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 62
kilroy is on a distinguished road
Default

I thought that's what he wanted? each sentence in a cell?

I tried putting "[.;:’””"/\!\*\?\\] " didn't work in macro but works in find replace function?
Reply With Quote
  #12  
Old 02-26-2019, 02:36 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,098
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

That's hardly consistent with:
Quote:
I am needing to copy and paste my word document into excel while retaining the same format and spacing.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #13  
Old 02-26-2019, 02:38 PM
kilroy kilroy is offline Windows 10 Office 2016
Advanced Beginner
 
Join Date: Sep 2016
Location: Southern Ontario
Posts: 62
kilroy is on a distinguished road
Default

Yes you're right as usual. I read the words and pictured something completely different. lol Sorry
Reply With Quote
  #14  
Old 02-26-2019, 05:03 PM
Guessed's Avatar
Guessed Guessed is online now Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,080
Guessed has a spectacular aura aboutGuessed has a spectacular aura aboutGuessed has a spectacular aura about
Default

Quote:
Originally Posted by pfittro View Post
It will retain the same formatting using a discrete paragraph for each line. Inserting the word document as an embedded object does not populate any cells. Instead it is just a floating block.
The purpose of this is to use excel to quickly draw a table in Revit with notes formatted in Word. Unfortunately Autodesk has not made Revit friendly to bringing in large blocks of notes from Word.
If there is a simple code for my original post please let me know.
There isn't simple code for your original post request. All hanging indented content you add paragraphs in will completely look different and if bulleted or numbered then that would end badly. You would use soft returns (line breaks) rather than paragraph marks to avoid that issue but the result is only marginally better.

I still don't see the problem, if I copy Word content and go to Excel and choose Paste Special > Microsoft Word Document Object (as you said you are doing) then the content appears with the same line wraps that the Word document had.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #15  
Old 02-26-2019, 07:27 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,098
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Even soft returns in Word result in the pasted content in Excel going to separate cells.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Tags
insert, paragraph character

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace a character only if it is at the beginning of the paragraph. donpopo Word 2 11-11-2018 11:32 PM
Add paragraph return between two specific character jeffreybrown Word 2 03-30-2017 02:45 PM
Can't get rid of Chinese character when inserting citation slavrenz Word 13 05-13-2015 11:47 AM
How to insert paragraph character after every 500 characters? aditya_bokade Word VBA 21 05-09-2014 03:56 AM
Replace paragraph-marks (line-breaks) in tables with a character-string Aztec Word VBA 2 04-02-2013 10:52 PM


All times are GMT -7. The time now is 04:01 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft