Hello Excel gurus,
I am new to this forum, this is my first posting, so my apologies in advance if I miss a posting rule...
Doing Excel VBA engineering automation just for fun, I am not a professional programmer.
Have a small code that calls a DOS program (spice.exe) through the Shell. It worked well with 32-bit Excels (in Windows7). I modified it to run in 64-bit Excel, by using Ptrsafe and LongLong, it works fine (on Windows10 and 64bit Excel). However, when I try to make a code that detects the version of Excel and use the lines starting with #If VBA7 = True ..., I get an error. I understand that the 64-bit Excel version will report the legacy part of code as an error and I should ignore it, but the 64bit Excel simply refuses to execute the macro (have not had a chance to try with 32bit Excel yet). Again, if I remove the lines involving the conditional compilation, and just include the function declaration for the corresponding Excel version, the code works OK either in 32bit or in 64bit Excels. I assume I am missing something very basic about conditional compilation. Below is the part of the code that gives me trouble. Can anyone give me a hint?
Thanks
I am new to this forum, this is my first posting, so my apologies in advance if I miss a posting rule...
Doing Excel VBA engineering automation just for fun, I am not a professional programmer.
Have a small code that calls a DOS program (spice.exe) through the Shell. It worked well with 32-bit Excels (in Windows7). I modified it to run in 64-bit Excel, by using Ptrsafe and LongLong, it works fine (on Windows10 and 64bit Excel). However, when I try to make a code that detects the version of Excel and use the lines starting with #If VBA7 = True ..., I get an error. I understand that the 64-bit Excel version will report the legacy part of code as an error and I should ignore it, but the 64bit Excel simply refuses to execute the macro (have not had a chance to try with 32bit Excel yet). Again, if I remove the lines involving the conditional compilation, and just include the function declaration for the corresponding Excel version, the code works OK either in 32bit or in 64bit Excels. I assume I am missing something very basic about conditional compilation. Below is the part of the code that gives me trouble. Can anyone give me a hint?
Thanks
Code:
Option Explicit
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] VBA7 = True Then
' 64 Bit API
Private Declare PtrSafe Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPtr
Private Declare PtrSafe Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As LongPtr, lpExitCode As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL]
' 32 bit API
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL] If
[/end code]