Excel Macro from 32 to 64 will not run

Pophil

New Member
Joined
Aug 3, 2016
Messages
25
Our work upgraded to Microsoft 365 and this has affected a macro that was run on 32,

1722268843779.png


Here is the original macro

VBA Code:
'                                     5/1/2013  .:\L0sT/:.

Private Declare  Function GetUserName Lib "advapi32.dll" _

    Alias "GetUserNameA" _

    (ByVal lpBuffer As String, _

    ByRef nSize As Long) As Long





And this is what i changed it to





'                                     5/1/2013  .:\L0sT/:.

Private Declare PtrSafe Function GetUserName Lib "advapi32.dll" _

    Alias "GetUserNameA" _

    (ByVal lpBuffer As String, _

    ByRef nSize As Long) As LongPtr

Also tried this

'                                     5/1/2013  .:\L0sT/:.

Private Declare PtrSafe Function GetUserName Lib "advapi32.dll" _

    Alias "GetUserNameA" _

    (ByVal lpBuffer As String, _

    ByRef nSize As Long) As Long



The macro will start to run then eventually close out the excel program.  What am I missing.  Thank you all for your help.





Also does this need to be changed as well for everything to work



'                                     5/1/2013  .:\L0sT/:.

Sub Clear_Temp_Files()

Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 "

End Sub

Sub Clear_Cookies()

Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2"

End Sub

Sub Clear_History()

Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1"

End Sub

Sub Clear_Form_Data()

Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16"

End Sub

Sub Clear_Saved_Passwords()

Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32"

End Sub

Sub Clear_All()

Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255"

End Sub

Sub Clear_Clear_Add_ons_Settings()

Shell "RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351"

End Sub

Sub Clear_4_Tool()

'

    Clear_Temp_Files

    Clear_Cookies

    Clear_History

End Sub
 
Last edited by a moderator:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Add PtrSafe before the word Function.

VBA Code:
Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
 
Upvote 0
Add PtrSafe before the word Function.

VBA Code:
Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Unfortunately it didn't work. It will start to run the code then it will close out the program and open it again saying repairing.
 
Upvote 0
That doesn't mean it didn't work. That means something doesn't work.
 
Upvote 0
I would step through the code in the VBA editor with F8.
 
Upvote 0
I would step through the code in the VBA editor with F8.
thank you for all the help. What I am finding is certain computers with the 64 bit update the program will not work and just close out. Other computers with the 64 bit update the PtrSafe fix works just fine. Any idea why this would happen.
 
Upvote 0
The declaration as 6SJ posted is correct. I don't know why you would bother with an API for this though when Environ("Username") does the same job.
 
Upvote 1
The declaration as 6SJ posted is correct. I don't know why you would bother with an API for this though when Environ("Username") does the same job.
Thank you, this was a program someone created a while ago. What I am finding is certain computers with the 64 bit update the program will not work and just close out. Other computers with the 64 bit update the PtrSafe fix works just fine. Any idea why this would happen.
 
Upvote 0
No, assuming you used the version 6SJ posted and not your version that returns a LongPtr (that is wrong). I'd assume something else is causing the issues.
 
Upvote 0

Forum statistics

Threads
1,221,419
Messages
6,159,800
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top