Unable to set Underline property of the Font class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I saw a very similar message posted 2 months ago but without a resolution. I am using Excel 2003, Windows 2000 Pro and get "Unable to set Underline property of the Font class" in my VBA code

Dim cActive As Rang
Set cActive = ActiveSheet.Range("$A$1"
With cActiv
With .Fon
If .Underline <> xlUnderlineStyleSingle Then .Underline = xlUnderlineStyleSingl
End Wit
End With
 
Hi
the following works for me:
Sub foo()
Dim cActive As Range
Set cActive = ActiveSheet.Range("$A$1")
With cActive
With .Font
If .Underline <> xlUnderlineStyleSingle Then .Underline =
xlUnderlineStyleSingle
End With
End With
End Sub


you may try:
Sub foo()
Dim cActive As Range
Set cActive = ActiveSheet.Range("$A$1")
With cActive
With .Font
If .Underline <> 2 Then .Underline = 2
End With
End With
End Sub
 
Thanks. I went ahead and tried this code outside of my application, and it worked for me also. There is something about my application that makes this fail. Still don't know what.
 
The solution was unprotecting the worksheet before changing the underline property. Excel 2003 has a new way of locking cells, and the cell was locked both from changing the content and changing the format. A different way of fixing it is to just lock the cells from changes in the GUI, which allows changes to still be made from the code.
 
Back
Top