View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default reference, test and change cell font.

A really great tool you have in Excel is the macro recorder. I entered some
text in a cell, then selected it, turned on the recorder and made the font
strikethrough. then I turned it off and looked at the recorded code. This
isn't a good way to program but it is a quick way to look at the properties
and how they are used.

With Selection.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = True
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With

so for your code

Sub TempPermHrs()
' a comment has a leading single quote
' once a single quote is encountered, that starts
' the quote - each line needs one
Dim state As Integer '// comment this out- how?
Set c = Range("F10")
c.Font.StrikeThrough = not c.Font.StrikeThrough

End sub

Note that the user can format individual characters. In which case, if a
single character is formatted as strikethrough rather than the whole cell,
then
c.Font.StrikeThrough would return NULL
End If


---
so just a demo from the immediate window:

activeCell.Font.Strikethrough = True
? activeCell.Font.Strikethrough
True
ActiveCell.Font.Strikethrough = False
? activeCell.Font.Strikethrough
False
ActiveCell.Characters(2,1).Font.Strikethrough = True
? activeCell.Font.Strikethrough
Null

--
Regards,
Tom Ogilvy



"feedscrn" wrote:

Hi All,

Excel VB is fun. I prefer MS C/C++, but I don't have the
compiler at work here... so....

I have the start of an Excel VB function... I would like to- via
a pushbutton to:
1. Test to see if the immediate left cell has strikeout font or
not.
2. If so, toggle to regular font.
2a. If regular font, toggle to strikeout.

This is for a timecard function... to say if the 'end time' is
tentative or not.

The pushbutton is set, with the basic structure. I don't know the
functions needed to reference, test or change the cell contents,
however :(

What I have so far, for a pushbutton in G10, is:
----------------------------------------------
Sub TempPermHrs()
Dim state As Integer // comment this out- how?
Set c = Range("F10")

End If
-----------------------------------------------

Thanks for any help,

Feedscrn


----------------------------------------------------------------------
When dinosaurs roamed the earth.. (hear the stomps in the background),
I started to learn Basic. I first learned some arcane commands: Peek
and Poke. That was enough to turn me off to the language for a long
time. VB is much more sophisticated now. It uses a 'DDEPoke Method'.
Everything is better now.. :-)
----------------------------------------------------------------------
Jesus Loves You ... John 3:16
----------------------------------------------------------------------