View Single Post
 
Old 01-18-2021, 07:25 PM
SMehta SMehta is offline Windows 10 Office 2013
Novice
 
Join Date: Jan 2021
Posts: 29
SMehta is on a distinguished road
Default

Sir, I've implemented your refined codes as per your post#4

What is the reason that this time your refined codes worked properly without any issues ?

Your Demo1 procedure pastes the full text file in Word document
Procedure changed from Demo to Demo4
The below code pastes the 2nd paragraph from 1st Blank line uptil the first blank line
after the 2 paragraph or after lines representing as 2nd paragrpah in notepad.

Code:
Sub Demo4()
Application.ScreenUpdating = False
Dim DocSrc As Document, DocTgt As Document
Set DocTgt = ActiveDocument: Set DocSrc = Documents.Open(FileName:="C:\Text-To-MsWord\Sample.txt", AddToRecentFiles:=False, Visible:=False)
With DocSrc
  With .Range
    With .Find
    .Format = False
    .Forward = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    .Text = "[^13]"
    .Replacement.Text = "^p"
    .Execute Replace:=wdReplaceAll
      .Wrap = wdFindStop
      .MatchWildcards = True
      .Text = "[^13]{2}[!^13]*[^13]{2}"
      .Replacement.Text = "^p"
      .Execute
    End With
    If .Find.Found = True Then
      DocTgt.Range.Characters.Last.Text = Replace(.Text, vbCr & vbCr, "")
    End If
  End With
  .Close False
End With
Application.ScreenUpdating = True
End Sub
Quote:
Perhaps you could explain what you are trying to achieve. Neither of your attachments makes that apparent.
Now I would like if i put values in following Textboxes From_Blank Line.Text and in To_BlankLine.Text to get the following text Pasted
From_Blank Line.Text = 10
To_BlankLine.Text = 14
Quote:
Jim takes the map to Squire Trelawney and Doctor Livesey who realise that it shows where Captain Flint, an evil and heartless pirate, has buried his stolen treasure. The Squire and the Doctor decide to go and find the treasure and invite Jim to come along. The Squire then buys a ship called the 'Hispaniola' and hires a crew led by the respected Captain Smollet. The ship's cook is a one legged man called Long John Silver whom everyone admires.
The above lines after Blank Line 10 and before Blank line14
So if i get a list of blank lines like from Notepad Structure
Blank lines are at 3
7
10
14
17
20
23

So knowing from blank line position i can paste the lines or paragraph between the blanklines.
would prefer something as From Blank Lines To BlankLines
3 7
7 10
10 14
14 17
17 20
20 23

Sir, in notepad 2nd paragraph shows with 3 lines and in Word Document it shows with 5 lines. I would prefer with notepad structure.

SMehta
Thread 1: No: 46342 : Post 6 : TM 6
Reply With Quote