PDA

View Full Version : Solved: Copying text from 7 textboxes via cmdButton



matty25
11-05-2008, 02:55 PM
I have the vba code to which enables me to copy text from several textboxes to the clipboard. The textboxes (1-7) are:

Company Name (TextBox 1)
Add Line 1
Add Line 2
Add Line 3
City
County
Post Code (TextBox 7)

The button works fine and copies the text from the textboxes to the clipboard so that i can use it in other programs eg. word.

I have now discovered that there isnt always a Address Line 3 and sometimes this box can be left blank.

Is there any code available to say if any of the textboxes (1-7) is blank or doesn't contain anything/any text, then not to include it in the copy function? So that when i paste it into word it only pastes the textboxes which have been filled in.

Many thanks, Matt

GTO
11-05-2008, 11:42 PM
Greetings Matt,

When you send it to Word, how is this being done? As one concentated string w/some linefeeds in it?

Maybe a code snippet to show how its currently working?

Mark

GTO
11-06-2008, 12:37 AM
Well, I don't know why it didn't strike me that it looks like envelope addressing the first time.

If so, or similar, here's a simple approach.

Hope this helps,

Mark

Option Explicit
Dim strAddress As String

Private Sub CommandButton1_Click()
Dim dObj As DataObject
With UserForm1
If Not .TextBox1 = Empty Then strAddress = strAddress & .TextBox1
If Not .TextBox2 = Empty Then strAddress = strAddress & vbCrLf & .TextBox2
If Not .TextBox3 = Empty Then strAddress = strAddress & vbCrLf & .TextBox3
If Not .TextBox4 = Empty Then strAddress = strAddress & vbCrLf & .TextBox4
If Not .TextBox5 = Empty Then strAddress = strAddress & vbCrLf & .TextBox5
If Not .TextBox6 = Empty Then strAddress = strAddress & vbCrLf & .TextBox6
If Not .TextBox7 = Empty Then strAddress = strAddress & vbCrLf & .TextBox7
End With

Set dObj = New DataObject

dObj.SetText strAddress, 1
dObj.PutInClipboard

End Sub

matty25
11-06-2008, 09:36 AM
Excellent, thanks GTO works a treat! :yes

Many thanks.

JKyleO
02-18-2015, 07:20 PM
I know this is old, but what was the entire code after it was completed?

mancubus
02-19-2015, 12:09 AM
welcome to the forum.

open a new thread and post your question to that thread please.
uploading your workbook (sensitive data replaced/removed) will help members help you.