PDA

View Full Version : 64 bit version



Asi
06-05-2011, 11:50 PM
Hi
I have an excel file that contains macro and is distributed to many stations and runs successfuly.
The code contains many Declare statements as the following:
Declare Function FindFirstFile Lib "kernel32" Alias _ "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData _ As WIN32_FIND_DATA) As Long

Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" _
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long

...


On 1 station, the following message occured: "The code in this project must be updated for use in 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute."
My questions are as follows:

Is this problem because the windows OS is 64-bit system or because Office is 64-bit version ?
Is there something I can do as a workaround on the stations that get this message or do I need to change my code ?
If changing the code is a must, can you give me an example of how to do that based on the example I mentioned above ?
Are there any other parts of the code that I need to check in order to make it compatible with 64-bit systems or only the Declare Statements ? Thanks
Asi

avtarxing
06-06-2011, 02:54 AM
Hi Asi

I believe your VBA Code should contain the PtrSafe tags for 64 bit versions of Office as in the below piece of code:

Declare PtrSafe Function FindFirstFile Lib "kernel32" Alias _ "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData _ As WIN32_FIND_DATA) As Long

Declare PtrSafe Function FindNextFile Lib "kernel32" Alias "FindNextFileA" _
(ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long

...




1. Is this problem because the windows OS is 64-bit system or because Office is 64-bit version ?

This is because of Office 64 bit version



2. Is there something I can do as a workaround on the stations that get this message or do I need to change my code ?

3. If changing the code is a must, can you give me an example of how to do that based on the example I mentioned above ?

Just add the PtrSafe keyword as shown above in the code snippet.
I have added the PtrSafe keyword to your piece of code snippet above.
Please try the above on your code and check.



4. Are there any other parts of the code that I need to check in order to make it compatible with 64-bit systems or only the Declare Statements ?

This is required only for the Declare Statements.


However you can write your code somewhat in the following manner:
######Just a Suggestion#####
#If VBA7 Then
Declare PtrSafe Function .....
#Else
Declare Function ......
#End If

Regards,

Avtar