Avatar of Skylar
Skylar
 asked on

How to add PtrSafe to make this work in 64 bit

I have this part of the code which is for 32 bit Excel and my excel is 64 bit,

I tried to make this 64 bit by adding PtrSafe at the beginining of the code. it did not work for me.

can anyone please help me?

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function ShellExecute Lib "shell32" _
    Alias "ShellExecuteA" _
   (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

Open in new window

VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Skylar

8/22/2022 - Mon
Zakaria Acharki

PtrSafe Asserts that a Declare statement is targeted for 64-bit systems. Required on 64-bits. so try to add it to the declaration like :

Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As Long
Private Declare PtrSafe Function ShellExecute Lib "shell32" 

Open in new window


For both version you could use a conditional declaration like :

#If Vba7 Then 
Private Declare PtrSafe Function ... 
#Else 
Private Declare Function ... 
#EndIf 

Open in new window

ASKER CERTIFIED SOLUTION
Daniel Pineault

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Skylar

ASKER
Thanks very much Daniel. It solved the problem.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23