Excel spreadsheet won't work on Windows 11

Robin Clay 30 Reputation points
2026-10-27T21:25:15.1166667+00:00

My Win 10 computer is 64-bit.
All my data is on six x 2Tb add-on hard-drives, with six more as back-up.
Over the past 45 years I have built up a library of VBA Routines, some of which have been given to me and I don't understand them ! But they do what I want !

When I got a Win11 computer, I simply unplugged the "manifold" from the Win 10 and plugged it into the Win 11.

But when I fired up an Excel spreadsheet, I got these messages that -

A) I do not understand, and

B) I have not the SLIGHTEST idea what to do !

Perhaps because I am now 87
(my father made it to 102)

I THINK I have added screen-shots of the two messages, but I can't see them !

So here are transcripts -
The first sez -

 Compile error:  
 The code in this project must be updated for use on 640bit  
 systems.  Please review and update Declare statements and  
 then mark them with the PtrSafe attribute.

Here's the start of the second - 

        Option Base 1
      Option Explicit

       

        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 "GetComputerNanteA" (

                                                                            ByVal lpBuffer As String,  nSize As Long) As Long

        ‘' The GetDirectory function         ‘ 32-bit API declarations

       

        Declare Function SHGetPathFromIDList Lib "shell32 .dll"

        Alias "SHGetPathFromIDListA"  (ByVal pidl As Long, ByVal pszPath As String) _

        As Long

       

        Public Declare Function SHBrowseForFolder Lib "shell32.dll" _

        Alias "SHBrowseForFolderA"  (lpBrowselnfo As BROWSEINFO) As Long_

       

and I guess the rest of that routine follows - and maybe others too.

In all the "upgrades", I have NEVER had SO many challenges ! :-(

So what can I do to solve this VBA challenge ?

Microsoft 365 and Office | Excel | Other | Windows
0 comments No comments

2 answers

Sort by: Newest
  1. Robin Clay 30 Reputation points
    2026-10-28T13:31:36.62+00:00

    Thank you, Rukshan !

    That solved those two but not the next two :-

    Declare Function PtrSafe SHGetPathFromIDList Lib "shell32.dll" _

    Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) _

    As Long

    Public Declare Function PtrSafe SHBrowseForFolder Lib "shell32.dll" _

    Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

    Was this answer helpful?


  2. Rukshan edirisinghe 2,365 Reputation points
    2026-10-28T02:17:57.72+00:00

    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.

    1. Open the workbook, press Alt + F11 to open the VBA editor, and find the module with the Declare lines.
    2. 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
    
    1. Do the same for any other Declare lines in your other modules: add PtrSafe after Declare. If a line deals with window handles or pointers (names like hWnd or lpSomething As Long), post it here, because those also need LongPtr.
    2. 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:

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.