Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 52
Default Function to return font style

Hi Basil
Public Function TextStyle(Reference As Range)
TextStyle = Range(Reference).Font.FontStyle
End Function

Cordially
Pascal

"Basil" a écrit dans le message de
...
Hi,

I've been looking for a function that will return the style of text within

a cell, but I can't find one!

I am aware that the text within a single cell can actually have multiple

styles, but I am not concerned with this.

So, I tried to create my own function in VBA which nearly works - but I

need help.

The VBA code in my personal module is as follows:

Public Function TextStyle(Reference)
TextStyle = Range(Reference).Font.FontStyle
End Function

The problem as you may have guessed is that Reference will return the

contents of the cell rather than the address (A1 or whatever). A way I
found around this was to change the way I use the function on the worksheet
eg:
=PERSONAL.XLS!TextStyle(ADDRESS(ROW(A1),COLUMN(A1) ,4))

This works, but I would rather just have it so I can say:
=PERSONAL.XLS!TextStyle(A1)

This is the first time I've actually created my own function in Excel, so

any help tips would be really welcomed.

Many thanks,

Basil
PS The function as is would return 0 for cells holding multiple styles



  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Function to return font style

Basil,

Here is something that you can modify to return what you want:

Use it like

=TextStyle(A1)

Changing the font doesn't trigger any event within Excel that you can
capture to force a recalc. The best you can do is force a recalc when the
selection changes...

Public Function TextStyle(Reference As Range) As String
With Reference.Font
If .Bold Then TextStyle = " Bold"
If .Italic Then TextStyle = TextStyle & " Italic"
If .Shadow Then TextStyle = TextStyle & " Shadow"
If .Underline = xlUnderlineStyleSingle Then TextStyle = TextStyle & "
Underline"

TextStyle = TextStyle & Chr(10) & "Name: " & .Name & Chr(10)
TextStyle = TextStyle & "ColorIndex: " & .ColorIndex & Chr(10)
TextStyle = TextStyle & "FontStyle: " & .FontStyle
End With
TextStyle = Trim(TextStyle)
End Function

HTH,
Bernie
MS Excel MVP

"Basil" wrote in message
...
I tried that already - it doesn't work (generate #VALUE error - I assume

because it expects Reference to be a range but it isn't - it's the cell
contents.)

Any other ideas?

Oh, also, do you know how I can get it to automatically update if I change

the target's font style?

Basil
PS when I say font style, I mean Bold/Italic etc

"papou" wrote:

Hi Basil
Public Function TextStyle(Reference As Range)
TextStyle = Range(Reference).Font.FontStyle
End Function

Cordially
Pascal

"Basil" a écrit dans le message de
...
Hi,

I've been looking for a function that will return the style of text

within
a cell, but I can't find one!

I am aware that the text within a single cell can actually have

multiple
styles, but I am not concerned with this.

So, I tried to create my own function in VBA which nearly works - but

I
need help.

The VBA code in my personal module is as follows:

Public Function TextStyle(Reference)
TextStyle = Range(Reference).Font.FontStyle
End Function

The problem as you may have guessed is that Reference will return the

contents of the cell rather than the address (A1 or whatever). A way I
found around this was to change the way I use the function on the

worksheet
eg:
=PERSONAL.XLS!TextStyle(ADDRESS(ROW(A1),COLUMN(A1) ,4))

This works, but I would rather just have it so I can say:
=PERSONAL.XLS!TextStyle(A1)

This is the first time I've actually created my own function in Excel,

so
any help tips would be really welcomed.

Many thanks,

Basil
PS The function as is would return 0 for cells holding multiple styles






  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,302
Default Function to return font style

Hi Pascal,

Change

TextStyle = Range(Reference).Font.FontStyle


to

TextStyle = ReferenceFont.FontStyle

You have already declared Reference as a range object.


---
Regards,
Norman



"papou" wrote in message
...
Hi Basil
Public Function TextStyle(Reference As Range)
TextStyle = Range(Reference).Font.FontStyle
End Function

Cordially
Pascal

"Basil" a écrit dans le message de
...
Hi,

I've been looking for a function that will return the style of text

within
a cell, but I can't find one!

I am aware that the text within a single cell can actually have multiple

styles, but I am not concerned with this.

So, I tried to create my own function in VBA which nearly works - but I

need help.

The VBA code in my personal module is as follows:

Public Function TextStyle(Reference)
TextStyle = Range(Reference).Font.FontStyle
End Function

The problem as you may have guessed is that Reference will return the

contents of the cell rather than the address (A1 or whatever). A way I
found around this was to change the way I use the function on the

worksheet
eg:
=PERSONAL.XLS!TextStyle(ADDRESS(ROW(A1),COLUMN(A1) ,4))

This works, but I would rather just have it so I can say:
=PERSONAL.XLS!TextStyle(A1)

This is the first time I've actually created my own function in Excel,

so
any help tips would be really welcomed.

Many thanks,

Basil
PS The function as is would return 0 for cells holding multiple styles





  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 60
Default Function to return font style

Thank you everyone. It works lovely now.

"Norman Jones" wrote:

Hi Pascal,

Change

TextStyle = Range(Reference).Font.FontStyle


to

TextStyle = ReferenceFont.FontStyle

You have already declared Reference as a range object.


---
Regards,
Norman



"papou" wrote in message
...
Hi Basil
Public Function TextStyle(Reference As Range)
TextStyle = Range(Reference).Font.FontStyle
End Function

Cordially
Pascal

"Basil" a écrit dans le message de
...
Hi,

I've been looking for a function that will return the style of text

within
a cell, but I can't find one!

I am aware that the text within a single cell can actually have multiple

styles, but I am not concerned with this.

So, I tried to create my own function in VBA which nearly works - but I

need help.

The VBA code in my personal module is as follows:

Public Function TextStyle(Reference)
TextStyle = Range(Reference).Font.FontStyle
End Function

The problem as you may have guessed is that Reference will return the

contents of the cell rather than the address (A1 or whatever). A way I
found around this was to change the way I use the function on the

worksheet
eg:
=PERSONAL.XLS!TextStyle(ADDRESS(ROW(A1),COLUMN(A1) ,4))

This works, but I would rather just have it so I can say:
=PERSONAL.XLS!TextStyle(A1)

This is the first time I've actually created my own function in Excel,

so
any help tips would be really welcomed.

Many thanks,

Basil
PS The function as is would return 0 for cells holding multiple styles






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
Changing font style and color using VBA Spongie Excel Discussion (Misc queries) 3 September 30th 09 08:34 PM
Change the Font Style in VBA justme0010[_2_] Excel Discussion (Misc queries) 1 January 15th 08 04:07 AM
font style of worksheet functions gvm Excel Worksheet Functions 4 January 20th 06 08:30 PM
changing font style in a complex worksheet function gvm Excel Worksheet Functions 6 August 3rd 05 01:29 AM
Icon button - font/style cvgairport Excel Discussion (Misc queries) 1 December 2nd 04 12:51 AM


All times are GMT +1. The time now is 11:54 PM.

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"