+ Reply to Thread
Results 1 to 4 of 4

VBA for 64-bit and 32-bit

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    VBA for 64-bit and 32-bit

    Hi,

    Below is code that works on 64-bit. I know by switching the LongLong's to Long and removing PtrSafe it works on 32-bit, but I'm wondering how to write this to work on both?

    Option Explicit
    Private mlngStart As LongLong
    Private Declare PtrSafe Function GetTickCount Lib "kernel32" () As LongLong
    
    
    Public Sub StartTimer()
           mlngStart = GetTickCount
    End Sub
    
    Public Function EndTimer() As LongLong
           EndTimer = (GetTickCount - mlngStart)
    End Function
    Last edited by yawnzzzz; 08-02-2010 at 08:55 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: VBA for 64-bit and 32-bit

    Good evening yawnzzzz

    Not tested, nor can I test it as I don't have Excel 2010 however I think you're going to need two versions of the macro: one for 32 bit and one for 64 bit. You will need to read the Application.Version value to see what the user is running and run the appropriate version.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Re: VBA for 64-bit and 32-bit

    From what I've gathered, this should work:

    Option Explicit
    #If VBA7 Then
    Private mlngStart As LongPtr
    #Else
    Private mlngStart As Long
    #End If
    
    #If VBA7 Then
    Private Declare PtrSafe Function GetTickCount Lib "kernel32" () As LongPtr
    #Else
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    #End If
    
    
    Public Sub StartTimer()
           mlngStart = GetTickCount
    End Sub
    But I'm not sure about the correct syntax for this:
    Public Function EndTimer() As LongPtr
           EndTimer = (GetTickCount - mlngStart)
    End Function

  4. #4
    Forum Contributor
    Join Date
    06-03-2008
    Posts
    387

    Re: VBA for 64-bit and 32-bit

    I just surrounded it like the above, and it appears to work. I thought there might be a simpler solution though.

    #If VBA7 Then
    IfPublic Function EndTimer() As LongPtr
           EndTimer = (GetTickCount - mlngStart)
    End Function
    #Else
    IfPublic Function EndTimer() As Long
           EndTimer = (GetTickCount - mlngStart)
    End Function
    #End

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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