Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default TEXTBOX COPY AND FORMAT !!


Hello -

On my userform, I have 2 questions:

1. How do I use vba to copy the contents of a textbox to the clipboard?

2. How do I format any 10-digit number I enter into a textbox to be of
the form ###-###-####. Example: entering 7891452236 in the textbox
should show as 789-145-2236.

Any help would be appreciated!
Thanks
Jay


*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default TEXTBOX COPY AND FORMAT !!



1. How do I use vba to copy the contents of a textbox to the clipboard?


Dim DataObj As New MSForms.DataObject
DataObj.SetText Me.TextBox1.Text
DataObj.PutInClipboard

2. How do I format any 10-digit number I enter into a textbox to be of
the form ###-###-####.


Allow only numeric values:

Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < Asc("0") Or KeyAscii Asc("9") Then
KeyAscii = 0
End If
End Sub

Format string:
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim S As String
Dim T As String
Dim N As Long

With Me.TextBox2
For N = 1 To Len(.Text)
Select Case Mid(.Text, N, 1)
Case "0" To "9"
T = T & Mid(.Text, N, 1)
Case Else
End Select
Next N
If Len(T) < 10 Then
Cancel = True
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
MsgBox "Invalid data"
Exit Sub
End If
S = Left(T, 3) & "-" & Mid(T, 4, 3) & "-" & Right(T, 4)
.Text = S
End With
End Sub


Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Sun, 26 Apr 2009 11:56:50 -0700, jay dean
wrote:


Hello -

On my userform, I have 2 questions:

1. How do I use vba to copy the contents of a textbox to the clipboard?

2. How do I format any 10-digit number I enter into a textbox to be of
the form ###-###-####. Example: entering 7891452236 in the textbox
should show as 789-145-2236.

Any help would be appreciated!
Thanks
Jay


*** Sent via Developersdex http://www.developersdex.com ***

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default TEXTBOX COPY AND FORMAT !!

Thanks, Chip ! In the second solutions, you have 2 functions? Do I just
assign them to textbox2 or they have to be assigned to a command button?


Thanks
Jay



*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default TEXTBOX COPY AND FORMAT !!


Please ignore my post on how to use 2nd solutions...I figured it out.
Thanks for all the help!

Jay


*** Sent via Developersdex http://www.developersdex.com ***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Textbox data to Textbox in Other File Troubled User Excel Programming 2 October 6th 08 06:42 PM
TextBox format? AOU Excel Discussion (Misc queries) 4 June 12th 07 11:24 PM
Textbox format Oggy Excel Programming 2 January 25th 07 06:30 PM
Textbox format Greg B[_4_] Excel Programming 4 March 21st 05 09:12 AM
Format Textbox as % Todd Huttenstine[_2_] Excel Programming 2 December 15th 03 12:07 AM


All times are GMT +1. The time now is 11:10 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"