function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Office toolkit and VBA Login invalid

Hi All,

I have gone through all of the posts on this board and have been unable to determine what my issue is.  I am using the below code to test the login but I keep getting invalid user name, password or token.  The user is set up to not have a token assigned through api and is working fine for all other apps we have running. 


Note I have removed the user id and password and just attached the code:


My question is two - fold:

1.  Do I need to have the excel connector installed to use the office toolkit API?

2.  Is there anything you can see that is wrong with the code below?



Dim g_sfApi As SForceOfficeToolkitLib3.SForceSession3
Public LoginTest As Boolean
Public myusername As String
Public mypassword As String
Public myserverurl As String
Public mymessage As String

Sub MyMain()
    LoginTest = True
    If LoginTest = True Then
        myusername = "
        mypassword = ""        'this might be different from below
        'mypassword = "password + token"        'this might be different from below
        myserverurl = ""
        myusername = ""
        mypassword = ""        'this might be different from above
        myserverurl = ""
    End If
If SampleLogin(myusername, mypassword) = True Then
    mymessage = "Logged into: " & g_sfApi.ServerUrl
    MsgBox mymessage
    mymessage = "Login failed, " & g_sfApi.ServerUrl & g_sfApi.ErrorField & g_sfApi.ErrorMessage
    MsgBox mymessage
    MsgBox (g_sfApi.ErrorField & g_sfApi.ErrorMessage)
    'Unload Me
End If

End Sub

Public Function SampleLogin(Username, Password) As Boolean
    Set g_sfApi = New SForceOfficeToolkitLib3.SForceSession3
    Debug.Print "Default URL: ", g_sfApi.ServerUrl
    If LoginTest = True Then
        g_sfApi.SetServerUrl (myserverurl)
        Debug.Print "New URL: ", g_sfApi.ServerUrl
    End If

    SampleLogin = g_sfApi.Login(Username, Password)
End Function



Thank you,




Save these bits into a .vbs file (enter your username and password) and run from the command line by typing in the name


Set g_sfApi = CreateObject("SForceOfficeToolkit3.SForceSession3")

if g_sfApi.Login (<your username>, <your password>) = False Then
    MsgBox (g_sfApi.ErrorMessage)
end if


No, you don't need the excel connector installed, the toolkit is a stand alone com object that is hosted by SF_MsApi.dll, which can be registered directly with regsvr32 SF_MsApi.dll


If that works for you, start to add more of your logic.



Thank you, I will give that a try and let you know.


Ok, so I am able to login with an id that has a generated security token.  What is different when trying to login in with an id that doesn't need to have a security token?




To my knowledge, there are no userid's that do not require tokens when not connecting through the FDC browser interface.