NewOrderFac33
Well-known Member
- Joined
- Sep 26, 2011
- Messages
- 1,283
- Office Version
- 2016
- 2010
- Platform
- Windows
Good afternoon,
We are going through a Win7/Office 2010 -> Win10/Office 2016 upgrade and some code that previously worked now no longer does.
In particular, I have a function to trap the ID of the currently logged on user thus:
When I open the workbooks containing these functions, the Public/Private Declare lines are highlighted in red. and all related functions and Procedures have to be commented out.
I'm bright enough to figure out that they're 32bit dll-related issues (kernel32.dll, user32.dll & advapi32.dll) but I don't know what the 64bit equivalents of my examples are!
Can anyone help, please?
As always, thanks in advance
Pete
We are going through a Win7/Office 2010 -> Win10/Office 2016 upgrade and some code that previously worked now no longer does.
In particular, I have a function to trap the ID of the currently logged on user thus:
Code:
-----------------------------------------------------------------------------------------------
Example 1 (Trapping Windows UserName)
-----------------------------------------------------------------------------------------------
Public Declare Function GETUSERNAME Lib "advapi32" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Called by:
Function GetWinUserName() As String
Dim szBuffer As String * 100
Dim lBufferLen As Long
lBufferLen = 100
If CBool(GETUSERNAME(szBuffer, lBufferLen)) Then
GetWinUserName = Left$(szBuffer, lBufferLen - 1)
Else
GetWinUserName = CStr(Empty)
End If
End Function
Called by:
Sub ShowWinUserName()
MsgBox (GetWinUserName)
End Sub
-----------------------------------------------------------------------------------------------
Example 2 (Trapping Screen resolution)
-----------------------------------------------------------------------------------------------
Public Declare Function GETSYSTEMMETRICS Lib "user32.dll" (ByVal nIndex As Long) As Long '
Called by:
Sub SetScreenResolution()
Dim x As Long
Dim y As Long
x = GETSYSTEMMETRICS(SM_CXSCREEN)
y = GETSYSTEMMETRICS(SM_CYSCREEN)
MsgBox ("Screen resolution = " & x & " X " & y)
End Sub
-----------------------------------------------------------------------------------------------
Example 3 (Trapping Computer Name)
-----------------------------------------------------------------------------------------------
'Private Declare Function GETCOMPUTERNAME Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Called by:
'Public Function NameOfComputer()
' Dim ComputerName As String
' Dim ComputerNameLen As Long
' Dim Result As Long
' ComputerNameLen = 256
' ComputerName = Space(ComputerNameLen)
' Result = GETCOMPUTERNAME(ComputerName, ComputerNameLen)
' If Result <> 0 Then
' NameOfComputer = Left(ComputerName, ComputerNameLen)
' Else
' NameOfComputer = "Unknown"
' End If
'End Function
Called by:
Sub ShowComputerName()
MsgBox (NameOfComputer)
End Sub
-----------------------------------------------------------------------------------------------
Example 4 (Trapping TEMP path variable)
-----------------------------------------------------------------------------------------------
'Private Declare Function GETTEMPPATH Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Const MAX_PATH As Long = 260
Called by:
Function TempPath() As String
TempPath = String$(MAX_PATH, Chr$(0))
GETTEMPPATH MAX_PATH, TempPath
TempPath = Replace(TempPath, Chr$(0), "")
End Function
Called by:
Sub ShowTempPath()
MsgBox (TempPath)
End Sub
-----------------------------------------------------------------------------------------------
When I open the workbooks containing these functions, the Public/Private Declare lines are highlighted in red. and all related functions and Procedures have to be commented out.
I'm bright enough to figure out that they're 32bit dll-related issues (kernel32.dll, user32.dll & advapi32.dll) but I don't know what the 64bit equivalents of my examples are!
Can anyone help, please?
As always, thanks in advance
Pete
Last edited: