Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Underline font not reporting properly
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 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Underline font not reporting properly
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. RobFMS wrote: 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 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Borders nor underline commands remove an unusual underline. ?? | Excel Discussion (Misc queries) | |||
Strikethrough and Underline Font Macro | Excel Worksheet Functions | |||
ACAD does not display Technic font properly in office 2003-why? | Excel Discussion (Misc queries) | |||
Unable to set Underline property of the Font class | Excel Programming | |||
Changing font size, bold and underline | Excel Programming |