2015-01-26 132 views
0

我無法爲Macintosh運行Excel,但由於Excel VBA編譯器常量VBA7是在Excel(針對Windows)2010中引入的,因此我認爲它也適用於Mac Excel 2011。Excel VBA編譯器常量:Mac Excel 2011 <> VBA7?

但是,顯然這個代碼時,在Mac的Excel 2011運行了「其他」部分(適用於Excel 2007中)編譯:

#If VBA7 Then 
    'Set constants here for Excel 2010 or later: 
#Else 
    'Set constants here for Excel 2007 or earlier: 
#End If 

因此,要得到它的誰是Mac的Excel 2011用戶工作,我不得不把它改成這樣:

#If VBA7 Or Mac Then 
    'Set constants here for Excel for Windows 2010 or later, or Excel for Mac: 
#Else 
    'Set constants here for Excel for Windows 2007 or earlier: 
#End If 

確實的Mac的Excel 2011真的沒有VBA7,或者是剛剛在編譯器不斷的疏忽?

回答

1

Excel for Mac仍然使用VBA 6.5,因此VBA7常量不存在。 Excel Mac 2016的v15.11(150609)仍然如此。

如果你真的想要主機Excel應用程序版本之間的區別,那麼你應該使用Application.Version

其中:

5 = Excel 5 
6 = Excel 6 
7 = Excel 95 
8 = Excel 97 
9 = Excel 2000 
10 = Excel 2002 
11 = Excel 2003 
12 = Excel 2007 
14 = Excel 2010 and Excel Mac 2011 
15 = Excel 2013 and Excel Mac 2016 

如果你想在VBA環境的版本,你可以使用: -

Application.VBE.Version