Click here to Skip to main content
15,909,898 members

Comments by himanshu_88 (Top 4 by date)

himanshu_88 29-Aug-12 12:56pm View    
Actually i don't want to delete spaces between words, what i want is to delete spaces between paragraphs.
I am using the below code(its just the for loop) to read data from a Word file, paragraph by paragraph and then display it into a text box on the form. But the spaces which are present between paragraphs are also being displayed on the text box(as the code is treating it as a paragraph).
Therefore, is there anything how i can filter out the spaces(or even some special characters) and then remove them before displaying in the text box.

For Each p In currentDocument.Paragraphs
Next p
himanshu_88 29-Aug-12 12:10pm View    
hi, i tried this code but it is not removing the spaces.
The empty spaces are still being shown on the text box as paragraphs.
himanshu_88 29-Aug-12 11:45am View    
Deleted
Imports System
Imports System.IO
Imports Microsoft.Office.Interop

Public Class Form1
Dim p, p1, line
Dim currentIndex As Integer
Dim list As New List(Of String)


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Dim myValue, path, Text1, myValue1, webBrowser1, email
Public Sub InputPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles InputPath.Click
path = InputBox("Input Path", "enter the path", "Path")
End Sub

Public Sub Notes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Notes.Click
myValue = InputBox("Probable Bugs", "Notes", "Notes")
myValue1 = myValue1 & vbCrLf & myValue
End Sub


Public Sub Display_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Display.Click
MsgBox(myValue1)
End Sub
Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort


Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objWord
Dim p
Dim wordPath
Dim currentDocument
Dim wscript
Dim num

wordPath = "C:\Users\c5167094\Desktop\123.docx"
objWord = CreateObject("Word.Application")
objWord.DisplayAlerts = 0
objWord.Documents.Open(wordPath, False, True)
currentDocument = objWord.Documents(1)




For Each p In currentDocument.Paragraphs
list.Add(p.range.text)
Next p

TextBox.Text = list(currentIndex)



currentDocument.Close()
currentDocument = Nothing
objWord.Quit()
objWord = Nothing
End Sub


Public Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
currentIndex = currentIndex + 1
TextBox.Text = List(currentIndex)

End Sub
End Class
himanshu_88 29-Aug-12 11:35am View    
will i be able to use trim() to delete all the spaces from an entire word document ?