A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi @Robin Clay
Moving your drives across worked fine. The messages come from the new computer having 64-bit Office, while your routines were written for 32-bit. Each Declare line at the top of a module needs the word PtrSafe before Excel will run it. Your workbooks and data are all fine.
Before changing anything, make a copy of the workbook, just in case.
- Open the workbook, press Alt + F11 to open the VBA editor, and find the module with the
Declarelines. - Replace your two lines with this block (it works on both 32-bit and 64-bit Excel):
#If VBA7 Then
Public Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare PtrSafe Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#Else
Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
#End If
- Do the same for any other
Declarelines in your other modules: add PtrSafe afterDeclare. If a line deals with window handles or pointers (names like hWnd or lpSomething As Long), post it here, because those also needLongPtr. - Select Debug > Compile VBAProject. If no message appears, save and run your routine as usual.
Could you paste the other Declare lines from your modules, so I can check them for you?
If your spreadsheets run again, please consider accepting it as the answer. If the compile step stops on another line, let me know and I'll be happy to keep helping.
Reference: