none
VBScript Not working for GetObject when we give Admin Rights RRS feed

  • Question

  • I was working with vbScript you can see the below code. It working fine when i run in normal mode but it not working when i start with Admin rights so can you explain why this is happening.

    Iam getting Error on [ GetObject(, "Excel.Application") ]

    ExcelFileName = "temp.xls"

    On Error Resume Next
    Set xl = GetObject(, "Excel.Application") 
    If Err Then
      If Err.Number = 429 Then
        WScript.Echo "Workbook not open (Excel is not running)."
      Else
        WScript.Echo Err.Description & " (0x" & Hex(Err.Number) & ")"
      End If
      WScript.Quit 1
    End If
    On Error Goto 0

    Set wb = Nothing
    For Each obj In xl.Workbooks
      If obj.Name = ExcelFileName Then 
        Set wb = obj
    wb.Close false
    Wscript.Echo "Excel is closed"
        Exit For
      End If
    Next
    If wb Is Nothing Then
      WScript.Echo "Workbook not open."
      WScript.Quit 1
    End If

    Monday, February 27, 2017 2:18 PM

Answers

  • First, Excel must be installed on the computer where the script is run. Second, once an error is raised, Excel is probably running on the computer and may cause errors when the script is run again. When an error is raised, used Task Manager (when you press cntrl-alt-del) to close any instances of Excel still in memory. Third, is it possible that Excel was installed for just the normal user, but no others?

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Proposed as answer by YLedEditor Monday, February 27, 2017 4:45 PM
    • Marked as answer by WhTurner33Editor Tuesday, March 21, 2017 2:00 PM
    Monday, February 27, 2017 2:46 PM

All replies

  • First, Excel must be installed on the computer where the script is run. Second, once an error is raised, Excel is probably running on the computer and may cause errors when the script is run again. When an error is raised, used Task Manager (when you press cntrl-alt-del) to close any instances of Excel still in memory. Third, is it possible that Excel was installed for just the normal user, but no others?

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Proposed as answer by YLedEditor Monday, February 27, 2017 4:45 PM
    • Marked as answer by WhTurner33Editor Tuesday, March 21, 2017 2:00 PM
    Monday, February 27, 2017 2:46 PM
  • Hi Mughilendran !

    You ask your question in the wrong forum.

    This forum answering questions concerning programming with the Small Basic software only.

    Have a good day !

    a good starting point would be:

    MSDN Visual Basic For Applications (VBA) forum

    • Edited by YLedEditor Monday, February 27, 2017 4:37 PM
    Monday, February 27, 2017 4:35 PM
    Answerer
  • This code uses to check excel file is open or not if i have to close it all then what is the use of this code, And its working fine when i run this script normally(without admin) but not working when i start this vbscript with admin.
    Friday, March 3, 2017 2:25 PM
  • Hi Mughilendran !

    This forum is for questions about Small Basic  langages only.

    For Visual Studio software questions here is the good forum:

    Visual Studio general forum

    Friday, March 3, 2017 2:39 PM
    Answerer
  • You should place your question here

    Scripting Forum

    Friday, March 3, 2017 9:50 PM
    Answerer