Toggle Font Styles Macro

G

GK80535

I'm trying to write a Macro that toggles through background color and
font styles.
No one's been able to help me out from my previous posts, so I'm still
searching.

I need a function that returns the current selection's font style (red,
italic, bold, times roman, etc.) so that I can store it in a variable
before my toggle begins and so that I can restore the style at the end
of my toggle. Can anyone please help me out with this?

Here's my code:

' Toggles the background color
' Keyboard Shortcut: Ctrl+Shift+O
Sub BackgroundToggle()
If Selection.Interior.ColorIndex = xlNone Then
Selection.Interior.ColorIndex = 2
ElseIf Selection.Interior.ColorIndex = 2 Then
Selection.Interior.ColorIndex = 1
Selection.Font.Color = RGB(255, 255, 255)
Selection.Font.Bold = True
ElseIf Selection.Interior.ColorIndex = 1 Then
Selection.Interior.ColorIndex = 48
Selection.Font.Color = RGB(255, 255, 255)
Selection.Font.Bold = True
ElseIf Selection.Interior.ColorIndex = 48 Then
Selection.Interior.ColorIndex = 35
Selection.Font.ColorIndex = 1
Selection.Font.Bold = True
Else
Selection.Interior.ColorIndex = xlNone
Selection.Font.Bold = False
Selection.Font.ColorIndex = 1
End If
End Sub
 
F

Frank Kabel

Hi
just define a varibale. e.g.

dim oldcolor
oldcolor=Selection.Interior.ColorIndex
 

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

Similar Threads

Toggle Font Style Macro 2
Toggle Font Style Macro 2
Format 6
allow change font while password pretected. 6
Change Cell color with macro 6
Problem with Macro 7
Excel Applying Code to a Column 0
Macro Continuous Execution 8

Top