0

I recently updated my Office applications to 365. I am getting an error in VBA. "Compile Error: The code in this project must be updated for use on 64-bit bit systems." How do I change the code to a 64 bit from a 32 bit?

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Erik A
  • 31,639
  • 12
  • 42
  • 67
J. McCormick
  • 15
  • 1
  • 6
  • 2
    Possible duplicate of [How should I make my VBA code compatible with 64-bit Windows?](https://stackoverflow.com/questions/5506912/how-should-i-make-my-vba-code-compatible-with-64-bit-windows) – Erik A Aug 17 '17 at 16:36
  • @ErikvonAsmuth perfect! I was trying to find another forum on this. – J. McCormick Aug 17 '17 at 16:45

1 Answers1

1

I just ran into this problem when preparing an Access database for 64 bit, and found this good code template for the compiler directives to ensure that the code works across multiple versions:

#if Vba7 then 
'  Code is running in the new VBA7 editor 
     #if Win64 then 
     '  Code is running in 64-bit version of Microsoft Office 
     #else 
     '  Code is running in 32-bit version of Microsoft Office 
     #end if 
#else 
' Code is running in VBA version 6 or earlier 
#end if 

Source: https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/64-bit-visual-basic-for-applications-overview

Jon Jaques
  • 21
  • 3