• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy textbox content to another texbox

Greg10956

New Member
Hello friends,
I have never posted to a forum but have benefited from the information within this site. Thanks to all who contribute your time an knowledge.... it's invaluable. My question concerns two drawing textboxes. I would like to copy the contents from textbox A to textbox B with VBA.
- Both textboxes are on the same Excel 2007 workbook in a single worksheet.
- Textbox B may contain text that would need to be deleted/cleared prior to pasting the new text from textbox A.
- The text in textbox A may vary in length and would need to be formatted to a specific font once pasted into textbox B (Ariel 10 for example).
- The original contents of textbox A would need to be deleted/cleared after pasting the text to textbox B.
Any assistance would be appreciated.
Thank you,
 
Greg

Firstly, Welcome to the Chandoo.org Forums

See if the attached does what you want?
 

Attachments

  • Greg.xlsm
    19.2 KB · Views: 2
Hui,
Thank u for the welcome and the example. I see it working well in the attached file but when I use the same logic in my file I receive an error message as follows: Run-time error '424': Object required. I think this may be because my textboxes were created using the Drawing toolbar.... not using the Developer toolbar > Forms textbox. Is there another option that might fit my circumstances? I would try to incorporate the solution into a pushbutton a user would click in order to execute the aforementioned steps.
Kind regards!
 
I would suggest using the developer Active X Controls, not the Form Controls or Text Boxes

can you post your file as a 424 error can be any number of issues
 
Hui,
Attached is a sample file where I would want to have a pushbutton kickoff vba that would copy the text in texbox 18 (approx. row 72) and paste the text into textbox 13 (approx. row 45). Please let me know if you believe Active X controls is the only way to proceed.
Many thanks,
greg
 

Attachments

  • sample_SE_Manager.zip
    68.8 KB · Views: 6
Hello Hui, please let me know if you had a chance to peek at the sample file with the textboxes. Any further thoughts would be greatly appreciated.
thank you,
greg
 
You can use the following methods to access the Textboxes text

Code:
Sheets(1).Shapes("textbox 13").TextFrame.Characters.Text = Sheets(1).Shapes("textbox 18").TextFrame.Characters.Text

or

Code:
Sheets("Manager_Self_Evaluation").Shapes("textbox 13").TextFrame.Characters.Text = Sheets("Manager_Self_Evaluation").Shapes("textbox 18").TextFrame.Characters.Text
 
Just a lil bit addition with HUI.

Code:
Sub trycopytexbox()
  With Sheet1
  'Just copy.
  .Shapes("textbox 13").TextFrame.Characters.Text = _
  .Shapes("textbox 18").TextFrame.Characters.Text
   
  'Just Color and underline
  .Shapes("textbox 13").TextFrame.Characters(5, 7).Font.Color = RGB(0, 0, 255)
  .Shapes("textbox 13").TextFrame2.TextRange.Characters(5, 7).Font.UnderlineStyle = msoUnderlineSingleLine
   
  'Add Hyperlink
  .Hyperlinks.Add .Shapes("textbox 13"), "http://www.chandoo.org/forum"
  End With
End Sub
 
Back
Top