Results 1 to 3 of 3

Thread: VBA Script locks the excel sheet

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    The irony is the below code doesn't lock the excel when running the VB script but the above one does.

    If Not IsObject(application) Then   Set SapGuiAuto  = GetObject("SAPGUI")
        Set application = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(connection) Then
        Set connection = application.Children(0)
    End If
    If Not IsObject(session) Then
        Set session    = connection.Children(0)
    End If
    If IsObject(WScript) Then
        WScript.ConnectObject session, "on"
        WScript.ConnectObject application, "on"
    End If
    session.findById("wnd[0]").maximize
    Dim objExcel, objWorkbook, objSheet, i
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open("C:\Users\TSK\User_Reset.xlsx")
    Set objSheet = objWorkbook.Sheets("Sheet1")
    For i = 2 to objSheet.UsedRange.Rows.Count
        USERID = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1
        PWD = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2
        session.findById("wnd[0]/tbar[0]/okcd").text = "su01"
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]/usr/ctxtUSR02-BNAME").text = USERID
        session.findById("wnd[0]/usr/ctxtUSR02-BNAME").caretPosition = 4
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]/tbar[1]/btn[20]").press
        session.findById("wnd[1]/usr/pwdG_PASSWORD1").text = PWD
        session.findById("wnd[1]/usr/pwdG_PASSWORD2").text = PWD
        session.findById("wnd[1]/usr/pwdG_PASSWORD2").setFocus
        session.findById("wnd[1]/usr/pwdG_PASSWORD2").caretPosition = 11
        session.findById("wnd[1]/tbar[0]/btn[0]").press
    next
    msgbox "Password reset completed"
    Last edited by Aussiebear; 05-16-2025 at 02:44 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •