Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2021, 12:32 AM
Bikram Bikram is offline Cleaning_texts Windows 10 Cleaning_texts Office 2007
Advanced Beginner
Cleaning_texts
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default Cleaning_texts


Hi to all, I am trying to copy and paste texts from pdf but the text contains many paragraph breaks that need to be removed if it is before a full stop. Or, we can replace all paragraph breaks from the selection and add paragraph breaks before starting of next sentences like (a., b., c.) followed by the first letter capital letter. Below is the sample text. Plz have a look. Looking forward to a solution.
Attached Files
File Type: docx Sample text.docx (15.7 KB, 11 views)
Reply With Quote
  #2  
Old 12-30-2021, 02:59 PM
macropod's Avatar
macropod macropod is offline Cleaning_texts Windows 10 Cleaning_texts Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See the Cleaning up Text Pasted from Websites, E-mails, PDFs etc. 'Sticky' post at the top of the Word forum: https://www.msofficeforums.com/word/...-pdfs-etc.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-30-2021, 10:56 PM
Bikram Bikram is offline Cleaning_texts Windows 10 Cleaning_texts Office 2007
Advanced Beginner
Cleaning_texts
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default

Thank you sir. It did a great job. But it removed all paragraph breaks what i need to do now is find full stop "." followed by "[a-z]." and insert a paragraphbreak before the text.
Code:
Sub Insertpara()
Dim str As String
Dim sbstr As String
Dim ix As Long
Dim times As Variant
Dim sblen As Long
Dim i As Integer
 Set rng = Selection.Range
    str = Selection.Range.Text
    sbstr = "." ' I checked the code using a full stop but i want to find "?." to find any character followed by full stop
    sublen = Len(sbstr)
    ix = 1
    occurences = -1
    Do
        times = times + 1
        idx = InStr(ix, str, substr, vbBinaryCompare) + sblen
      
        Selection.Range.Characters(ix).InsertAfter (Chr(13))
               
       
    Loop While ix > sblen
End Sub
I gathered and modified the above code that i copy and pasted from a website it does work fine for the first times(occurences) but from the second time, it is not accurate. Can you please help to modify the code as per my requirement? Thanks in advance sir.
Reply With Quote
  #4  
Old 01-02-2022, 03:17 PM
macropod's Avatar
macropod macropod is offline Cleaning_texts Windows 10 Cleaning_texts Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Please read the comments in the thread...
Quote:
Note also that the process assumes there are at least two such paragraph breaks between the 'real' paragraphs.
There is no reliable way for a macro (or Find/Replace) to determine where paragraphs really end without something like that.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Other Forums: Access Forums

All times are GMT -7. The time now is 02:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft