带有32位标志的Excel 2016条件编译

时间:2016-10-02 03:35:38

标签: macos excel-vba excel-2016 vba excel

在今天通过更新获得的OSX上新的64位版Excel 2016中,在检查没有定义PtrSafe的函数定义时似乎没有遵循条件编译(如同适用于32位平台)。在这个例子中,我们对不同的平台有相同功能的不同定义,当Excel加载加载项时,它会死掉,并抱怨第三个定义在函数声明中没有PtrSafe(但当然它没有#t; t因为它适用于32位平台)。

有没有办法让Excel在VBA中遇到此代码时不会死?或者这只是OSX上64位Excel 2016中的一个错误?对我来说似乎是一个明显的错误。我在哪里报告Excel中的错误?

#If Mac Then
' Even though the functions are exported with a leading underscore, Excel 2011 for Mac doesn't want the leading underscore as part of name
Private Declare PtrSafe Function get_global_param_string_private Lib "libCoolProp.dylib" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
#ElseIf Win64 Then
Private Declare PtrSafe Function get_global_param_string_private Lib "CoolProp_xls_x64.dll" Alias "get_global_param_string" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
#Else
Private Declare Function get_global_param_string_private Lib "CoolProp_xls_std.dll" Alias "_get_global_param_string@12" (ByVal param As String, ByVal Output As String, ByVal n As Integer) As Long
#End If

This is the error from Excel

1 个答案:

答案 0 :(得分:1)

除非64位和32位窗口的API函数本身不同,否则对Windows使用VBA7开关(从Office 2010开始)就足够了:

import random
HANGMANPICS = ['1', '2', '3', '4', '5', '6']
words = {"Easy":"blah1 blah2 blah3".split(),
         "Medium":"blah4 blah5 blah6".split(),
         "Hard":"blah7 blah8 blah9".split()}

def getRandomWord(wordDict, difficulty):
    wordKey = difficulty
    wordGrab = random.randint(0, len(wordDict[wordKey]) - 1)
    return [wordDict[wordKey][wordGrab]]

def displayASCII(HANGMANPICS, wrongGuesses, rightGuesses, fullWord):
    print(HANGMANPICS[len(wrongGuesses)])
    print()

    print("Missing letters:", end= " ")
    for guess in wrongGuesses:
        print(guess, end = " ")
    print()

    blanks = "_" * len(fullWord)
    for i in range(len(fullWord)):
        print("_", end = " ")
    print()

    for i in range(len(fullWord)):
        if fullWord[i] in rightGuesses:
            blanks = blanks[:i] + fullWord[i] + blanks[i+1:]

            for x in blanks:
                print(x, end=" ")
            print()

def getGuess(alreadyGuessed):

    while True:
        print("Guess a letter.")
        guess = input()
        guess = guess.lower()
        if len(guess) != 1:
            print("Just ONE letter, cheater.")
        elif guess in alreadyGuessed:
            print("Maybe something you HAVEN'T already tried.")
        elif guess not in "abcdefghijklmnopqrstuvwxyz":
            print("How about a LETTER big guy")
        else:
            return guess

def chooseDifficulty(listOfKeys):
    counter = 0
    for i in listOfKeys:
        print(str(counter) + ":" + str(i))
        counter += 1
    difficulty = input("Choose a difficulty (0, 1 or 2): ")
    while difficulty not in "0 1 2".split():
            difficulty = input("Choose a difficulty (0, 1 or 2): ")
    print("Difficulty set to: " + listOfKeys[int(difficulty)])
    return listOfKeys[int(difficulty)]


print("H A N G M A N")
wrongGuesses = ""
rightGuesses = ""
keys = list(words.keys())
difficulty = chooseDifficulty(keys)
fullWord = getRandomWord(words, difficulty)

while True:
    displayASCII(HANGMANPICS, wrongGuesses, rightGuesses, fullWord)

    guess = getGuess(wrongGuesses + rightGuesses)