|
-
Aug 1st, 2019, 01:06 PM
#1
Thread Starter
Junior Member
Excel Macro VB Mismatch error
Hi everybody,
I hope this is the right place to post this. I was looking to get some feedback on a mismatch error I'm getting in Visual Basic. I have inherited a custom macro created to run in an Excel spreadsheet. The business that I am working with, would like this updated to work with the newer version of the software. I'm not super proficient in Visual Basic's, more of a newbe.
Anyway, I'm getting a mismatch error I was hoping somebody could look at the picture below and perhaps give me some input on what I should correct?

here is the code too
Code:
Option Explicit
Declare PtrSafe Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As LongPtr
Public Function OpenAuthenticate() As String
Load frmAuthenticate 'Load the authentication form
frmAuthenticate.Show 'Make the form visible to the user
'Get the username back from the form
OpenAuthenticate = frmAuthenticate.strValue
'MsgBox "Value returned from frmAuthenticate: " & OpenAuthenticate
'Unload the form from memory
Unload frmAuthenticate
End Function
Public Function Get_Network_User() As String
'Return the network login name of the local user
Dim slength As LongPtr ' length of the string
Dim username As LongPtr
Dim retval As LongPtr ' return value
' Create room in the buffer to receive the returned string.
username = Space(255) ' room for 255 characters
slength = 255 ' initialize the size of the string
' slength is now the length of the returned string
' Get the user's name
retval = GetUserName(username, slength)
If retval = 0 Then
Get_Network_User = "" 'retval=0 if an error occured in GetUserName
Else
Get_Network_User = Left(username, slength - 1) ' extract the returned info from the buffer
'(We subtract one because we don't want the null character at the end of the trimmed string.)
End If
End Function
Last edited by Siddharth Rout; Aug 2nd, 2019 at 06:55 AM.
Reason: Inserted Code Tags
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|