|
|
Thread Tools | Display Modes |
#16
|
|||
|
|||
Quote:
Quote:
The above Two text files were attached to show the different structure of text file where there are empty lines Regardless as there are 7 paragraph in Sample.txt and 15 paras in Sample2.txt. Any paragrah or group of any Selected non empty lines in txt file ie after geting the avaialble list of Blank lines should be copied on Plain word Document one after another (As per the desired selection of Available Blank line Nos). Rule.1 : Getting list of Empty Blank Line Nos of a Text Files in Sample.txt file I would like to get the List of following Blank lines nos 3 7 so data from line 4 to 6 are non-empty 7 10 so data from line 8 to 9 are non-empty 10 14 so data from line 11 to 13 are non-empty 14 17 so data from line 15 to 16 are non-empty 17 20 so data from line 18 to 19 are non-empty 20 23 so data from line 21 to 22 are non-empty if i select for eg for 1st time blank lines Textbox:FromBlank Line 10 and Textbox:To Blank Line14 then data from lines 11 to 13 get copied into New plain Word document at First line of doc Then if i select blank lines Textbox:FromBlankLine20 Textbox:ToBlankLine 23 then data of non empty lines 21 to 22 to get copied after lines 11 to 13 Selection of Data should be on desired choice of Avaialble List of Blank line nos Rule.2 : Presentation Structure After each Selection which gets copied. i would like to have Empty line beween each copied data into new word doc Quote:
Sir, Anything be Sequentially selected after geting the list of available blank line nos from (at present Defined Sample.Txt )any text files and get copied into plain doc. Sir and your Demo version showed the First instance of data between the first and next empty line geting copied into new word doc and not on the basis of selecting on the available list of blank Lines which being copied into New Word Doc SMehta Thread 1: No: 46342 : Post No16 : TM 9 |
#17
|
|||
|
|||
Yet another link found
Check for empty or blank lines while reading a text file I really don't know whether the code in above link, pasted below, is a VBA code. ??? if not then how can we use the same VBA word to get the list of Blank line numbers from text file Would really appreciate your input and guidance. Code:
Option Strict On Option Explicit On Option Infer Off Imports System.IO.Path Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles MyBase.Load Dim desktop As String = _ Environment.GetFolderPath(Environment.SpecialFolder.Desktop) Dim textFilePath As String = _ Combine(desktop, "ExampleTextFile.txt") Dim blankLines() As Integer = GetBlankLines(textFilePath) Stop End Sub Private Function GetBlankLines(ByVal textFilePath As String) As Integer() Dim retVal() As Integer = New Integer() {} If Not String.IsNullOrWhiteSpace(textFilePath) Then If IO.File.Exists(textFilePath) Then Dim lineNumber As Integer = 1 Dim tempList As New List(Of Integer) Using rdr As New System.IO.StreamReader(textFilePath) Do While rdr.Peek() >= 0 Dim itm As String = rdr.ReadLine.Trim If String.IsNullOrWhiteSpace(itm) Then tempList.Add(lineNumber) End If lineNumber += 1 Loop End Using If tempList.Count > 0 Then retVal = tempList.ToArray End If End If End If Return retVal End Function End Class Thread 1: No: 46342 : Post No17 : TM 10 |
#18
|
|||
|
|||
Any other practical way with VBA coding to achieve what i want.
I am stuck badly. SMehta Thread 1: No: 46342 : Post No18 : TM 11 |
#19
|
||||
|
||||
It is not clear what you are looking for. What is it that the code has to do?
'Lines' is not something you should be looking at - the terminology which makes sense is 'paragraphs'. The number of lines depends on a range of variables such as the window size or font size/paper size. The number of paragraphs is fixed. If you want to remove the blank 'paragraphs' then you don't need to know what their numbers are, you just need to remove them. The code Paul supplied previously will do that.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#20
|
||||
|
||||
Thank you very much for your reply Dear Andrew Sir
Quote:
I am so sorry. Please bear with me as this is my First Thread. Quote:
Basically with Sir Paul's code will it be possible to come out with List of Empty Paragraph position in the document . In this case the code was executed to see the (pasted or copied) paragraph was the 1st paragraph of the file Sample.txt if not mistaken ie it showed the paragraph with text after the 1st Empty Paragraph position and before the 2nd Empty Paragraph position. Then in this case my question would be "Can i have the List of No(s) of Each position of Empty Paragraphs ? ". If Yes then how do i get list of each position of Empty Paragraph in the document. As I see the SPACING too plays an important role representing a gap as empty paragraph which is not an Empty Paragraph as per "MS-Word" terminology. Also here the link which indicates the same Microsoft Word Help, Tips and Tutorials @ The Anchorage I will be glad if the above is resolved. As this will be one part. And after understanding the above then i shall be intrested in getting the below solved Quote:
Quote:
SMehta Thread 1: No: 46342 : Post No20 : TM 12 |
#21
|
||||
|
||||
To return the paragraph numbers for empty (or just spaces) paragraphs you could do a loop like this
Code:
Sub GetUsedParas() Dim aPar As Paragraph, sList As String, i As Long For i = 1 To ActiveDocument.Paragraphs.Count If Len(Trim(ActiveDocument.Paragraphs(i).Range.Text)) = 1 Then sList = sList & "," & i End If Next i MsgBox Mid(sList, 2), vbInformation + vbOKOnly, "Empty Paragraphs List" End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#22
|
|||
|
|||
Quote:
I copied the data from Sample.Txt from Notepad to Word Document to check. Removed "Add Space after Paragraph", font is Calibri and size is 11 in word doc. Will it be possible on which line or Empty Paragraph is positioned ? So therefore Will i be able to get Following list of Empty Paragraph positioned at 4, 10, 15, 21, 26, 30, 34 SMehta Thread 1: No: 46342 : Post No22 : TM 13 |
#23
|
||||
|
||||
Yes, for some reason, the imported paragraph marks are coming up as double characters (probably a vbCrLf rather than a vbCr).
I've altered the code so it deals with that Code:
Sub GetUsedParas() Dim sList As String, i As Long, sText As String For i = 1 To ActiveDocument.Paragraphs.Count sText = Trim(ActiveDocument.Paragraphs(i).Range.Text) 'Debug.Print Len(sText) If Split(sText, vbCr)(0) = "" Then sList = sList & "," & i End If Next i MsgBox Mid(sList, 2), vbInformation + vbOKOnly, "Empty Paragraphs List" End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#24
|
|||
|
|||
Andrew Sir,
The below code was just Fantastic. Code:
Sub GetUsedParas() Dim sList As String, i As Long, sText As String For i = 1 To ActiveDocument.Paragraphs.Count sText = Trim(ActiveDocument.Paragraphs(i).Range.Text) 'Debug.Print Len(sText) If Split(sText, vbCr)(0) = "" Then sList = sList & "," & i End If Next i MsgBox Mid(sList, 2), vbInformation + vbOKOnly, "Empty Paragraphs List" End Sub Now coming back to Paul's Sir remark on his post #12 Quote:
Quote:
Thread 1: No: 46342 : Post No24 : TM 14 |
#25
|
||||
|
||||
If you know how to define the range where the file needs to be inserted then you just do that
Code:
Dim aRng As Range Set aRng = ActiveDocument.Paragraphs(3).Range aRng.InsertFile FileName:="C:\Text-To-MsWord\Sample.txt", ConfirmConversions:=False, Link:=False, Attachment:=False
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia Last edited by Guessed; 02-03-2021 at 12:06 AM. Reason: Amended code |
#26
|
|||
|
|||
I get Type Mistmatch Error 13
on the following line Code:
ActiveDocument.Range.InsertFile FileName:="C:\Text-To-MsWord\Sample.txt", Range:=aRng, ConfirmConversions:=False, Link:=False, Attachment:=False SMehta Thread 1: No: 46342 : Post No26 : TM 15 |
#27
|
||||
|
||||
Yep, I fixed the issue in the code I posted. Try
Code:
aRng.InsertFile FileName:="C:\Text-To-MsWord\Sample.txt", ConfirmConversions:=False, Link:=False, Attachment:=False
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#28
|
|||
|
|||
Sir,
This time no error. Representation of the result is quoted after the code Wanted the result as quoted in Post #24 FYI i am also not aware of other syntaxes of VBA Word. Your guidance will be appreciated. Code:
Sub InsertParafrom() Dim DocSrc As Document Dim DocTgt As Document Set DocSrc = ActiveDocument 'Set DocTgt = Documents.Open(FileName:="C:\Text-To-MsWord\Sample2.txt", AddToRecentFiles:=False, Visible:=False) Dim aRng As Range Set aRng = DocSrc.Paragraphs(4).Range aRng.InsertFile FileName:="C:\Text-To-MsWord\Sample2.txt", ConfirmConversions:=False, Link:=False, Attachment:=False End Sub Quote:
Thread 1: No: 46342 : Post No28 : TM 16 |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need help to get data from notepad to word | ganesang | Word VBA | 2 | 08-11-2019 10:21 PM |
Word does not stop at the set tab, but it keeps forever on the same line like it would in Notepad. | danvina@gmail.com | Word | 2 | 01-16-2019 02:33 PM |
Microsoft notepad over word for saving important text files | Noclip1 | Word | 1 | 10-25-2017 10:55 PM |
Copy text with tab at start of line and paste to Notepad | JohnTurnbull | Word | 5 | 08-27-2017 11:17 PM |
Sr. Citizen Question, Please: WORD Shows Blank, But Notepad Shows "Gibberish" ? | Robert11 | Word | 3 | 08-12-2013 12:35 PM |