Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #17  
Old 01-25-2021, 10:24 PM
SMehta SMehta is offline Notepad to Word : Pasting Specific text ie between any two blank line from notepad to word Windows 10 Notepad to Word : Pasting Specific text ie between any two blank line from notepad to word Office 2013
Novice
Notepad to Word : Pasting Specific text ie between any two blank line from notepad to word
 
Join Date: Jan 2021
Posts: 29
SMehta is on a distinguished road
Default

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
SMehta
Thread 1: No: 46342 : Post No17 : TM 10
Reply With Quote
 



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
Notepad to Word : Pasting Specific text ie between any two blank line from notepad to word Microsoft notepad over word for saving important text files Noclip1 Word 1 10-25-2017 10:55 PM
Notepad to Word : Pasting Specific text ie between any two blank line from notepad to word Copy text with tab at start of line and paste to Notepad JohnTurnbull Word 5 08-27-2017 11:17 PM
Notepad to Word : Pasting Specific text ie between any two blank line from notepad to word Sr. Citizen Question, Please: WORD Shows Blank, But Notepad Shows "Gibberish" ? Robert11 Word 3 08-12-2013 12:35 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:19 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