Text Box - Moving Formatted Text

T

Troubled User

I am moving text from one textbox (from the drawing toolbar) on one sheet to
another textbox (on another sheet). I used these textboxes to allow for
copy/paste functionality, which I couldn't make work using the ControlToolbox
Textboxes . Anyway, when I move the data using the function below, It does
not move the formats (underline / bold) of the moved text. Any help would be
appreciated.

Thank you.

Sub moveit

Dim x1 As Integer
Dim Source1 As TextBox
Dim Target1 As TextBox
Dim Text1 As String

Set Source1 = sht1.DrawingObjects(1)
Set Target1 = sht2.DrawingObjects(1)

For x1 = 1 To Source1.Characters.Count Step 250

' Place the first text box text into a variable called theText.
Text1 = Source1.Characters(Start:=x1, Length:=250).Text

' Place the value of theText variable into second text box.
Target1.Characters(Start:=x1, Length:=250).Text = Text1

Next

End Sub
 
J

Jim Rech

I think your choices are to either copy the text box as a whole or to set
the each character's bold and underline property one at a time.
 
T

Troubled User

I don't want to copy the entire textbox (for multiple reason, including that
I am doing this to about 50 different textboxes) anyway, I will try to write
something that moves them one at a time with a test for bold / underline for
each.

Thanks for your help. You will probably hear from me again!
 
T

Troubled User

Jim,

OK, I worked on this for several hours before seeing your response. I will
trust your judgement on altering the font after all the text has been moved.
So now I need to step through the source text character by character and
testing the font for bold and underlining. I created two string variables to
do this :

Dim TextBold As String
Dim TextUnd As String

I then changed the length to 1 via:

Text1 = Source1.Characters(Start:=x1, Length:=1).Text

and have tried to test Text1 using multiple different methods however I
can't get anything to return other than Invalid Qualifer errors. This got me
thinking that when I load the value into Text 1 that it need to have all its
text/font qualities, which I am not sure is the case if you load using .Text
as is above. Any help is greatly appreciated.

Thanks for any help you can provide. I will keep trying.
 
J

Jim Rech

This worked for me. I assumed that characters can be both bold and
underlined, btw.

Sub TransferBoldAndUnderline()
Dim TB1 As TextBox
Dim TB2 As TextBox
Dim Counter As Integer
Set TB1 = Sheet1.TextBoxes("Text Box 1")
Set TB2 = Sheet2.TextBoxes("Text Box 1")
For Counter = 1 To TB1.Characters.Count
If TB1.Characters(Counter, 1).Font.Bold Then
TB2.Characters(Counter, 1).Font.Bold = True
End If
If TB1.Characters(Counter, 1).Font.Underline Then
TB2.Characters(Counter, 1).Font.Underline = True
End If
Next
End Sub
 
T

Troubled User

Jim,

I ran it and was getting some strange results (still bolding what shouldn't
be) so I added the following to the start of the function to clear and reset
and it work perfectly:

TB2.Text = ""
TB2.Characters.Font.Bold = False
TB2.Characters.Font.Underline = False

Thanks for all your help!
 
J

Jim Rech

I ran it and was getting some strange results

I should have said that my code assumed you had just run code that copied
the text into the second text box and that the second box was totally
unformatted. Anyway, all's well that ends well.<g>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top