Friday, February 24, 2012

Application.Evaluate

In Excel 2011 Application.Evaluate is broken

For example the test macro below will show you 1 in Excel 2004 and all Windows Excel versions.
Sub TestAppEvaluate()
    ThisWorkbook.Names.Add "Version", "=1"
    MsgBox Application.Evaluate("'" & ThisWorkbook.Name & "'!Version")
End Sub

But in Excel 2011 this will not work, you can use this as a workeround :
Sub TestAppEvaluate2()
    Dim VersionConstant As String
    ThisWorkbook.Names.Add "Version", "=2"
    VersionConstant = ThisWorkbook.Names("Version").RefersTo
    MsgBox Mid(VersionConstant, 2, Len(VersionConstant) - 1)
End Sub

No comments:

Post a Comment