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:
and here is my userform code:
However, I get a compile error when attempting to run the code on the tablet computer. The error is as follows:
I don't have any experience with converting 32bit VBA macros to 64bit.
Any help is greatly appreciated! Thanks!
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!