Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy range Cell text and font properties to a Textbox

I have a spreadsheet cell that I would like to copy not only it's text but
it's Font properties to a textbox object. Since a single cell could have
several different font attributes per each character, how do you accomplish
this without setting each character's font one by one.

Hopefully there is a better way!!!!

---------------------------------------------------------------------
Example code looks like (if needed):

Place some text into A1 on a spreadsheet and change some font attributes
(i.e. bold, size, boldness, color...) on some of the letters in the text.
Add a textbox somewhere on the page (don't change the name, it should
default to "Text Box 1").

Below is the code:

Option Explicit
Sub TryIt()

Dim i As Integer, acell As Range, tb As TextBox, f As Font

Set acell = ActiveSheet.Range("A1")
Set tb = ActiveSheet.TextBoxes("Text Box 1")

'--- copy the text
tb.Text = acell.Text

'--- copy the font attributes one-by-one.... ugggg!!!!
For i = 1 To acell.Characters.Count

Set f = acell.Characters(i, 1).Font

With tb.Characters(i, 1).Font
.Bold = f.Bold
.Color = f.Color
.ColorIndex = f.ColorIndex
.FontStyle = f.FontStyle
.Italic = f.Italic
.Name = f.Name
.OutlineFont = f.OutlineFont
.Shadow = f.Shadow
.Size = f.Size
.Strikethrough = f.Strikethrough
.Subscript = f.Subscript
.Superscript = f.Superscript
.Underline = f.Underline
End With

Next

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Copy range Cell text and font properties to a Textbox

BC,

Textboxes don't support the character by character formatting that cells
allow - at least, the standard textboxes don't have a .Character property.

HTH,
Bernie
MS Excel MVP

"BC" wrote in message
...
I have a spreadsheet cell that I would like to copy not only it's text but
it's Font properties to a textbox object. Since a single cell could have
several different font attributes per each character, how do you

accomplish
this without setting each character's font one by one.

Hopefully there is a better way!!!!

---------------------------------------------------------------------
Example code looks like (if needed):

Place some text into A1 on a spreadsheet and change some font attributes
(i.e. bold, size, boldness, color...) on some of the letters in the text.
Add a textbox somewhere on the page (don't change the name, it should
default to "Text Box 1").

Below is the code:

Option Explicit
Sub TryIt()

Dim i As Integer, acell As Range, tb As TextBox, f As Font

Set acell = ActiveSheet.Range("A1")
Set tb = ActiveSheet.TextBoxes("Text Box 1")

'--- copy the text
tb.Text = acell.Text

'--- copy the font attributes one-by-one.... ugggg!!!!
For i = 1 To acell.Characters.Count

Set f = acell.Characters(i, 1).Font

With tb.Characters(i, 1).Font
.Bold = f.Bold
.Color = f.Color
.ColorIndex = f.ColorIndex
.FontStyle = f.FontStyle
.Italic = f.Italic
.Name = f.Name
.OutlineFont = f.OutlineFont
.Shadow = f.Shadow
.Size = f.Size
.Strikethrough = f.Strikethrough
.Subscript = f.Subscript
.Superscript = f.Superscript
.Underline = f.Underline
End With

Next

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy range Cell text and font properties to a Textbox

Bernie,

Thanks for looking. The problem is that there are two different textbox
objects. One is a VB textbox object (can be created by having the toolbar
"Control Toolbox" visible and selecting the "Text Box" icon) and the other
is an Drawing textbox object (can be created by having the toolbar "Drawing"
visible and selecting the "Text Box" icon). MS sure wants to make it
difficult....

If you look at the example: Set tb = ActiveSheet.TextBoxes("Text Box 1")
which is different if you were to use a Form TextBox. ie. Set tb =
ActiveSheet.TextBox1

Sorry about the confusion! But I'm asking about the Drawing TextBox.

Brett

The example I posted does work and the textbox object does support the

..Character property.
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message

...
BC,

Textboxes don't support the character by character formatting that cells
allow - at least, the standard textboxes don't have a .Character property.

HTH,
Bernie
MS Excel MVP

"BC" wrote in message
...
I have a spreadsheet cell that I would like to copy not only it's text

but
it's Font properties to a textbox object. Since a single cell could

have
several different font attributes per each character, how do you

accomplish
this without setting each character's font one by one.

Hopefully there is a better way!!!!

---------------------------------------------------------------------
Example code looks like (if needed):

Place some text into A1 on a spreadsheet and change some font attributes
(i.e. bold, size, boldness, color...) on some of the letters in the

text.
Add a textbox somewhere on the page (don't change the name, it should
default to "Text Box 1").

Below is the code:

Option Explicit
Sub TryIt()

Dim i As Integer, acell As Range, tb As TextBox, f As Font

Set acell = ActiveSheet.Range("A1")
Set tb = ActiveSheet.TextBoxes("Text Box 1")

'--- copy the text
tb.Text = acell.Text

'--- copy the font attributes one-by-one.... ugggg!!!!
For i = 1 To acell.Characters.Count

Set f = acell.Characters(i, 1).Font

With tb.Characters(i, 1).Font
.Bold = f.Bold
.Color = f.Color
.ColorIndex = f.ColorIndex
.FontStyle = f.FontStyle
.Italic = f.Italic
.Name = f.Name
.OutlineFont = f.OutlineFont
.Shadow = f.Shadow
.Size = f.Size
.Strikethrough = f.Strikethrough
.Subscript = f.Subscript
.Superscript = f.Superscript
.Underline = f.Underline
End With

Next

End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Copy range Cell text and font properties to a Textbox

BC,

My apologies. It looks like you do need to do it property-wise, as your
code shows.

HTH,
Bernie
MS Excel MVP


"BC" wrote in message
.. .
Bernie,

Thanks for looking. The problem is that there are two different textbox
objects. One is a VB textbox object (can be created by having the toolbar
"Control Toolbox" visible and selecting the "Text Box" icon) and the other
is an Drawing textbox object (can be created by having the toolbar

"Drawing"
visible and selecting the "Text Box" icon). MS sure wants to make it
difficult....

If you look at the example: Set tb = ActiveSheet.TextBoxes("Text Box

1")
which is different if you were to use a Form TextBox. ie. Set tb =
ActiveSheet.TextBox1

Sorry about the confusion! But I'm asking about the Drawing TextBox.

Brett

The example I posted does work and the textbox object does support the

.Character property.
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message

...
BC,

Textboxes don't support the character by character formatting that cells
allow - at least, the standard textboxes don't have a .Character

property.

HTH,
Bernie
MS Excel MVP

"BC" wrote in message
...
I have a spreadsheet cell that I would like to copy not only it's text

but
it's Font properties to a textbox object. Since a single cell could

have
several different font attributes per each character, how do you

accomplish
this without setting each character's font one by one.

Hopefully there is a better way!!!!

---------------------------------------------------------------------
Example code looks like (if needed):

Place some text into A1 on a spreadsheet and change some font

attributes
(i.e. bold, size, boldness, color...) on some of the letters in the

text.
Add a textbox somewhere on the page (don't change the name, it should
default to "Text Box 1").

Below is the code:

Option Explicit
Sub TryIt()

Dim i As Integer, acell As Range, tb As TextBox, f As Font

Set acell = ActiveSheet.Range("A1")
Set tb = ActiveSheet.TextBoxes("Text Box 1")

'--- copy the text
tb.Text = acell.Text

'--- copy the font attributes one-by-one.... ugggg!!!!
For i = 1 To acell.Characters.Count

Set f = acell.Characters(i, 1).Font

With tb.Characters(i, 1).Font
.Bold = f.Bold
.Color = f.Color
.ColorIndex = f.ColorIndex
.FontStyle = f.FontStyle
.Italic = f.Italic
.Name = f.Name
.OutlineFont = f.OutlineFont
.Shadow = f.Shadow
.Size = f.Size
.Strikethrough = f.Strikethrough
.Subscript = f.Subscript
.Superscript = f.Superscript
.Underline = f.Underline
End With

Next

End Sub








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
textBox font colour the same as cell font colour???????? Sophie Excel Discussion (Misc queries) 4 February 13th 09 10:15 AM
copy cell font colour to textbox? Sophie Excel Discussion (Misc queries) 0 January 28th 09 01:03 AM
Copy/paste text in cells into a textbox ian123[_40_] Excel Programming 1 January 5th 04 11:03 PM
How to copy text from a TextBox in a ActiveSheet to a variable Tom Ogilvy Excel Programming 2 August 19th 03 06:35 PM
How to copy text from a TextBox in a ActiveSheet to a variable pat Excel Programming 0 August 19th 03 05:06 PM


All times are GMT +1. The time now is 04:51 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"