Userform Tablet Orientation - Compile Error

infazz

Board Regular
Joined
Sep 19, 2014
Messages
60
Hello!

Using the information from VBA and Tablet Orientation this thread and https://msdn.microsoft.com/en-us/library/ms812142.aspx this MSDN article, I'm attempting to create a macro that will adjust a userform based on the orientation of tablet.

Here is my module code:
Code:
Option Explicit


Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long


Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long


Public Const GWL_WNDPROC = -4
Public Const WM_DISPLAYCHANGE = 126
Global lpPrevWndProc As Long
Global gHW As Long


Public Sub Hook()
    lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
    AddressOf WindowProc)
End Sub


Public Sub Unhook()
    Dim temp As Long
    temp = SetWindowLong(gHW, GWL_WNDPROC, _
    lpPrevWndProc)
End Sub


Function WindowProc(ByVal hw As Long, ByVal uMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As _
Long
    'Activated when display changes
    If uMsg = WM_DISPLAYCHANGE Then
        'Separate the width and height and then
        'check to see if screen width is greater than screen height
        If lParam Mod &H10000 > lParam \ &H10000 Then
            'Run the application in landscape, for example:
            MsgBox "Run in landscape."
        Else
            'Run the application in portrait, for example:
            MsgBox "Run in portrait."
        End If
    End If
    'Pass windows messages on to the default WindowProc
    WindowProc = CallWindowProc(lpPrevWndProc, hw, _
    uMsg, wParam, lParam)
End Function

and here is my userform code:
Code:
Private Sub Form_load()
    gHW = Me.hwnd
    Hook
End Sub


Private Sub Form_Terminate()
    Unhook
End Sub

However, I get a compile error when attempting to run the code on the tablet computer. The error is as follows:
Code:
Compile Error:

The code in this project must be updated for use on 64-bit systems.
Please review and update Declare statements and then mark them with the ptrSafe attribute.

I don't have any experience with converting 32bit VBA macros to 64bit.

Any help is greatly appreciated! Thanks!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Forum statistics

Threads
1,195,952
Messages
6,012,500
Members
441,702
Latest member
chacham

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
Top