+ Reply to Thread
Results 1 to 15 of 15

32 bit and 64 bit compatability

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    32 bit and 64 bit compatability

    So I am working on a project for my father-in-law's business and I just sent what I have right now to him to test it and he came up with an error saying that it needs to be updated to function with 64bit. I have put over 40 hours into this worksheet and I don't want to lose it all. What kind of changes would I need to make to make it compatible?

    Here is the spreadsheet if that helps. (Some of my macros aren't complete yet either so just ignore those ones.) Thanks for any help you can provide.
    Inventory Management Accounting.xlsm
    Last edited by manofcheese; 06-12-2014 at 02:31 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: 32 bit and 64 bit compatability

    I think that only your APIs will need updating, take a look here http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

  3. #3
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: 32 bit and 64 bit compatability

    As far as I know I didn't use any API's. But I could be wrong. I am pretty new to VBA.

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: 32 bit and 64 bit compatability

    You are, that's why I said it

  5. #5
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: 32 bit and 64 bit compatability

    Could you give me an example of some API's that I used in my attached spreadsheet? I really don't know what they are and I also don't know how to change them.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: 32 bit and 64 bit compatability

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
      (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
      (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
      (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    
    Private Const GWL_STYLE = (-16)
    Private Const WS_CAPTION = &HC00000
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const WS_SYSMENU = &H80000
    
    Private Declare Function SetWindowPos Lib "user32" _
      (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
      ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
      ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Private Enum ESetWindowPosStyles
      SWP_SHOWWINDOW = &H40
      SWP_HIDEWINDOW = &H80
      SWP_FRAMECHANGED = &H20
      SWP_NOACTIVATE = &H10
      SWP_NOCOPYBITS = &H100
      SWP_NOMOVE = &H2
      SWP_NOOWNERZORDER = &H200
      SWP_NOREDRAW = &H8
      SWP_NOREPOSITION = SWP_NOOWNERZORDER
      SWP_NOSIZE = &H1
      SWP_NOZORDER = &H4
      SWP_DRAWFRAME = SWP_FRAMECHANGED
      HWND_NOTOPMOST = -2
    End Enum
    
    Private Declare Function GetWindowRect Lib "user32" _
      (ByVal hwnd As Long, lpRect As RECT) As Long
    
    Private Type RECT
      Left As Long
      Top As Long
      Right As Long
      Bottom As Long
    End Type
    The link I posted explains how to deal with 64-bit compatibility

  7. #7
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: 32 bit and 64 bit compatability

    So are API's basically the private sub codes that I use for my buttons?

  8. #8
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: 32 bit and 64 bit compatability

    So on the link you gave me it has this code. From what I understand, if I put this at the beginning of my macros then it should solve it. Is that correct?
    ' Test whether you are using the 64-bit version of Office 2010.
    #If Win64 Then
       Declare PtrSafe Function GetTickCount64 Lib "kernel32" () As LongLong
    #Else
       Declare PtrSafe Function GetTickCount Lib "kernel32" () As Long
    #End If

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: 32 bit and 64 bit compatability

    Are you actually using the code in the NoTitle module?

    I can't see it being called anywhere.
    If posting code please use code tags, see here.

  10. #10
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: 32 bit and 64 bit compatability

    Oh yeah. I forgot about that one. I am not currently using it but I plan to use it once I get more done. So if I got rid of this code or fixed this part would it be compatible?

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: 32 bit and 64 bit compatability

    It'd probably be a better idea to keep it and change it to be compatible.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: 32 bit and 64 bit compatability

    No - that's an example of how to make an API call compatible (its not an API function you are using). You need to apply the same principle to the actual function declarations you are using.
    Everyone who confuses correlation and causation ends up dead.

  13. #13
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: 32 bit and 64 bit compatability

    So if I understand correctly my code would be like this?
    Private If Win64 Then Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
      (ByVal lpClassName As String, ByVal lpWindowName As String) As LongLong
    Else
     Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
      (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    End if
    
    Private If Win64 Then Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
      (ByVal hwnd As LongLong, ByVal nIndex As LongLong, ByVal dwNewLong As LongLong) As LongLong
    else
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
      (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    end if
    Or something like that?

  14. #14
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: 32 bit and 64 bit compatability

    Not quite. Your module would become something like this:

    #If Win64 Then
        Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
          (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
        
        Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" _
            (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
        
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" _
                        (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr
                        
        Private Declare PtrSafe Function SetWindowPos Lib "user32" _
              (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, _
              ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
              ByVal cy As Long, ByVal wFlags As Long) As Long
          
        Private Declare PtrSafe Function GetWindowRect Lib "user32" _
          (ByVal hwnd As LongPtr, lpRect As RECT) As Long
          
    #Else
        Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
          (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
        
        Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
          (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        
        Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
          (ByVal hwnd As Long, ByVal nIndex As Long) As Long
        Private Declare Function SetWindowPos Lib "user32" _
          (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
          ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
          ByVal cy As Long, ByVal wFlags As Long) As Long
        Private Declare Function GetWindowRect Lib "user32" _
          (ByVal hwnd As Long, lpRect As RECT) As Long
    #End If
    
    Private Const GWL_STYLE = (-16)
    Private Const WS_CAPTION = &HC00000
    Private Const WS_MAXIMIZEBOX = &H10000
    Private Const WS_MINIMIZEBOX = &H20000
    Private Const WS_SYSMENU = &H80000
    
    
    Private Enum ESetWindowPosStyles
      SWP_SHOWWINDOW = &H40
      SWP_HIDEWINDOW = &H80
      SWP_FRAMECHANGED = &H20
      SWP_NOACTIVATE = &H10
      SWP_NOCOPYBITS = &H100
      SWP_NOMOVE = &H2
      SWP_NOOWNERZORDER = &H200
      SWP_NOREDRAW = &H8
      SWP_NOREPOSITION = SWP_NOOWNERZORDER
      SWP_NOSIZE = &H1
      SWP_NOZORDER = &H4
      SWP_DRAWFRAME = SWP_FRAMECHANGED
      HWND_NOTOPMOST = -2
    End Enum
    
    
    Private Type RECT
      Left As Long
      Top As Long
      Right As Long
      Bottom As Long
    End Type
    
    Sub Title_Show()
      Application.DisplayScrollBars = True
      ActiveWindow.DisplayHeadings = True
      ShowTitleBar True
    End Sub
    
    Sub Title_Hide()
      Application.DisplayScrollBars = False
      ActiveWindow.DisplayHeadings = False
      ShowTitleBar False
    End Sub
    
    Sub ShowTitleBar(bShow As Boolean)
        #If Win64 Then
            Dim xlHnd As LongPtr
            Dim lStyle As LongPtr
        #Else
          Dim xlHnd As Long
          Dim lStyle As Long
        #End If
      Dim tRect As RECT
      
      xlHnd = Application.hwnd
    
      '// Get the window's position:
      GetWindowRect xlHnd, tRect
    
      '// Show the Title bar ?
      If Not bShow Then
        lStyle = GetWindowLong(xlHnd, GWL_STYLE)
        lStyle = lStyle And Not WS_SYSMENU
        lStyle = lStyle And Not WS_MAXIMIZEBOX
        lStyle = lStyle And Not WS_MINIMIZEBOX
        lStyle = lStyle And Not WS_CAPTION
      Else
        lStyle = GetWindowLong(xlHnd, GWL_STYLE)
        lStyle = lStyle Or WS_SYSMENU
        lStyle = lStyle Or WS_MAXIMIZEBOX
        lStyle = lStyle Or WS_MINIMIZEBOX
        lStyle = lStyle Or WS_CAPTION
      End If
    
      SetWindowLong xlHnd, GWL_STYLE, lStyle
    
      Application.DisplayFullScreen = Not bShow
    
      '// Ensure the style is set and makes the xlwindow the
      '// same size, regardless of the title bar.
      SetWindowPos xlHnd, 0, tRect.Left, tRect.Top, tRect.Right - tRect.Left, _
        tRect.Bottom - tRect.Top, SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
    End Sub

  15. #15
    Forum Contributor
    Join Date
    05-24-2014
    MS-Off Ver
    Microsoft Office 2013
    Posts
    113

    Re: 32 bit and 64 bit compatability

    Thanks for the code. I put it in my spreadsheet and we will see how it works for my brother in law. I'll let you know how it goes as soon as I hear back from him.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Compatability Mode
    By Macdave_19 in forum Excel General
    Replies: 2
    Last Post: 09-30-2008, 04:40 AM
  2. Compatability issues
    By Jack_Feeman in forum Excel General
    Replies: 1
    Last Post: 06-29-2006, 09:35 AM
  3. Backward compatability
    By Michael Beckinsale in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-01-2006, 12:30 PM
  4. VB backwards compatability
    By mike in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-10-2005, 11:05 AM
  5. PIA compatability
    By Irfan in forum Excel General
    Replies: 1
    Last Post: 07-15-2005, 12:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1