PDA

View Full Version : Delete line from textbox that has an empty field



simpleonline
01-27-2011, 10:14 AM
I can't seem to figure out how to begin with this here. I have a textbox and a button in a word doc.

I am going to paste in a rough template (that changes) and I need to be able to click the button and remove any blank lines from the template.

How would I go about this? I'm a C# programming but I can wing VBA.

Thanks

Bill Date From - A:
12/19/10

Bill Date Through - A:
present

Location - A:

Invoices Only - A: Yes

Packing Items - A: Yes

Insurance on Package - A: Yes

fumei
01-27-2011, 10:40 AM
1. what vesion of Word?

2. what kind of textbox?

3. your example is not helpful. We do not know what is it supposed to end up like

4. "remove any blank lines from the template." Then do not have blank lines in the template in the first place. Is it a real template - .dot?

simpleonline
01-27-2011, 12:13 PM
Version is Microsoft Word 2003

Textbox was created using Visual Basic Tool Bar in Word

I need the button to remove the spaces between the lines like this

Bill Date From - A: 12/19/10
Bill Date Through - A: present
Invoices Only - A: Yes
Packing Items - A: Yes
Insurance on Package - A: Yes


Hope this helps....thanks

I've attached the word doc to this thread so you guys can get an idea of what I'm working with....the above info is copied from a form and pasted into the textbox on the screen.

fumei
01-27-2011, 12:44 PM
1. You are not using Option Explicit. I strongly recommend you start using it immediately.

2. What exactly is the purpose of posting that file? It looks nothing like your example; and the code for the button do nothing exact display a message...that they do not do anything. It seems completely irrelevant to what you are asking about.

"I've attached the word doc to this thread so you guys can get an idea of what I'm working with....the above info is copied from a form "

Copied from a form? WHAT form? A userform from another document?

I copied:
Bill Date From - A: 12/19/10
Bill Date Through - A: present
Invoices Only - A: Yes
Packing Items - A: Yes
Insurance on Package - A: Yes

into a textbox (by the way, WHY are you using a textbox????). It does NOT have spaces betwen the paragraphs, so...there are no spaces in the text in the textbox.

Problem solved?

My point is that if the text string you are putting into the textbox has "extra" paragraphs...take them out. As it certainly is not clear where this text is coming from, it is hard to suggest how to do this.

You have not answer my question about if it is a real template.

If the text has been selected, you can strip out "empty" paragraphs with something like:

Dim oPara As Paragraph
For Each oPara In Selection.Range.Paragraphs
If Asc(oPara.Range.Text) = 13 Then
oPara.Range.Delete
End If
Next
This will NOT work if you are picking up the text from a userform. This is not a Selection.

Please try and give more details.

fumei
01-27-2011, 12:48 PM
Is th text from a userform, from a textbox with multi-line = true (so it can have those extra paragraphs.

BTW: those extra paragraphs are simple BAD habits. As much as possible try to not have them in the first place.

simpleonline
01-27-2011, 01:13 PM
Okay I think I'm going to scratch the whole text box thing.....maybe you guys can help me with this one instead.


Let's say that I copy text from a web application that we have at work...it's a company coded app so it wouldn't help if I give the name of it....

The text is pre-formatted with double spaces in the web app. We can copy the text from the app and paste it into a word doc....manually we have to go through each line and delete out any spaces between the lines as some of the info is needed and some is not....so before was can process the info the users have to manually take out the spaces between each line...seems like a small task but when you deal with hundreds of lines a day it gets tedious.

Is is possible to copy the info from that app to a blank word doc and code up a button to remove any spaces if they are blank?

****Not a template per say....I just called it a template because we use templates around here....sorry for the mix-up....thanks you guys for dealing with me....

fumei
01-27-2011, 01:49 PM
"Is is possible to copy the info from that app to a blank word doc and code up a button to remove any spaces if they are blank?"

Absolutely yes. You could do a version of the code I posted previously:
Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If Asc(oPara.Range.Text) = 13 Then
oPara.Range.Delete
End If
Next
Or, use Find and Replace.
With ActiveDocument.Range.Find
.ClearFormatting
.Text = "^p^p"
.Replacement.Text = "^p"
.Execute Replace:=wdReplaceAll
End With
Find and Replace would be faster.

Do make sure that these "lines" are in fact paragraphs!