Writing VBA in Excel 2007 for use in Excel 2003

后端 未结 5 1557
甜味超标
甜味超标 2021-01-12 12:23

Where I\'m at the developers have been updated to Excel 2007, but most of the users haven\'t. I\'m building a spreadsheet template (*.xlt) for a user that\'s gonna need som

5条回答
  •  离开以前
    2021-01-12 13:04

    One difference I discovered is that a subroutine must have a different signature to be called from a menu (in Excel 2003) than when called from the ribbon (in Excel 2007). Whatsmore, Excel 2003 doesn't recognise IRibbonControl and throws compile errors.

    To work toward cross-version compatability, I use a Conditional Compilation Argument and then check that in pre-processor macros.

    e.g.

    #If USINGRIBBON Then
        Public Sub CallFromRibbon(control As IRibbonControl)
    #Else
        Public Sub CallFromRibbon()
    #End If
        ' Code here
       End Sub
    

    This does mean that you have to save one version of your add-in with the USINGRIBBON flag set to false (for Excel2003) and another with the USINGRIBBON flag set to true (for Excel2007), but this is far easier than maintaining two completely separate codebases.

提交回复
热议问题