Underline font not reporting properly

R

RobFMS

I would like to hear from other individuals who either have experienced this
issue and/or have resolved the issue.

When I am running the Excel automation process, I cannot accurately
determine if a cell has the Underline font set (See the code below). I have
extracted the code and structured it in such a way to illustrate the issue I
have discovered.

The problem is: Excel reports back that the cell DOES have the underline
font set even though it is not set (i.e. value returned is TRUE).

I am running this code from Access (2000 or higher).

Your input/assistance is appreciated.
Rob



Test Code
----------------------
Private m_Excel As Excel.Application
Private m_Workbook As Excel.Workbook
Private m_ActiveSheet As Excel.Worksheet

' Make sure that you set the references to either Excel 2000, 2002, or 2003
'
Public Sub TestUnderline()

Dim fValue As Boolean

Set m_Excel = New Excel.Application
m_Excel.Visible = True

Set m_Workbook = m_Excel.Workbooks.Add
Set m_ActiveSheet = m_Workbook.ActiveSheet

' Put some value in the cell
m_ActiveSheet.Range("A1").Value = "ABC123"

' Determine if the underline font has been set
fValue = m_ActiveSheet.Range("A1").Font.Underline

' Display the results
MsgBox Prompt:=fValue, Title:="Is the font 'Underline' set for the cell?"

m_Workbook.Close SaveChanges:=0

m_Excel.Quit

Set m_Excel = Nothing

End Sub


--
Rob

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
D

Dave Peterson

Try declaring fValue as a Long.

You'll see that you get -4142 back -- by coercing this value into a boolean,
you're getting a True (non-zero).

The .underline can be
xlUnderlineStyleNone
xlUnderlineStyleSingle
xlUnderlineStyleDouble
xlUnderlineStyleSingleAccounting
xlUnderlineStyleDoubleAccounting

And if you open up the immediate window and type:
?xlunderlinestylenone
you'll see:
-4142

If you want:

m_ActiveSheet.Range("A1").Value = "ABC123"
m_ActiveSheet.Range("A1").font.underline = xlunderlinestyleSingle ' =2

Then try it.
 

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

Top