Jump to content

Excel error office not activated


Recommended Posts

Hi, I have this script but sometimes it gives me an error "The requested action with this object has failed", the error occurs when I run the script in a machine which Office is not activated, it pops up a window to activate office and messes, sometimes it runs perfectly but sometimes I get an error, is there a way to fix it? if there's no way I'll have to check if Office is installed and skip this code if is not activated.

Also, I'd be glad if someone tells me the way to get the path to Office, it depends on the version installed, for example, "Program files(x86)\Microsoft office\Office15\" or Ir could be a different number, I'd like to know the way to get the final path

Global $oWorkBook = ""
Global $oAppl = ""
Global $oAppl = _Excel_Open(False)
Global $oWorkbook = _Excel_BookOpen($oAppl, "C:\new.xlsx") ; your workbook here

local $Obj = ObjEvent($oWorkbook, "Workbook_")
         $Obj.DisplayAlerts = False

         Global $xlUp = -4162
         ;Both
         With $oWorkbook.Sheets(1)
            Global $UltimaCeldaBoth = .Cells(.Rows.Count, "A").End($xlUp).row       ;
            Global $UltimaCeldaBothCelda = .Cells(.Rows.Count, "A").End($xlUp).row      ;
            $UltimaCeldaBoth = _Excel_RangeRead($oWorkbook, 1, "A1:E" & $UltimaCeldaBoth, 2)
         EndWith
         

         With $oWorkbook.Sheets(2)
            Global $UltimaCeldaRegular = .Cells(.Rows.Count, "A").End($xlUp).row        ;
            Global $UltimaCeldaRegularCelda = .Cells(.Rows.Count, "A").End($xlUp).row       ;
            $UltimaCeldaRegular = _Excel_RangeRead($oWorkbook, 2, "A1:E" & $UltimaCeldaRegular, 2)
         EndWith
         
         
         With $oWorkbook.Sheets(3)
            Global $UltimaCeldaIrregular = .Cells(.Rows.Count, "A").End($xlUp).row      ;
            Global $UltimaCeldaIrregularCelda = .Cells(.Rows.Count, "A").End($xlUp).row     ;
            $UltimaCeldaIrregular = _Excel_RangeRead($oWorkbook, 3, "A1:E" & $UltimaCeldaIrregular, 2)
         EndWith

 

Edited by luis713
Link to post
Share on other sites

We use KMS but here is how I tend to activate office (simplified version of my script).

#NoTrayIcon
Opt("ExpandVarStrings", 1)
Global $g_sKMS_HostName = "KMSServer.local"
Global $g_sKMS_PortName = "1688"
Global $g_sMSO_FilePath = RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\EXCEL.EXE", "Path")
    If FileExists($g_sMSO_FilePath) = 0 Then Exit

Global $g_sMSO_FileVersion = Round(FileGetVersion(RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\EXCEL.EXE", ""))) & ".0"
ConsoleWrite("Office Path: " & $g_sMSO_FilePath & @CRLF)
ConsoleWrite("Office Version: " & $g_sMSO_FileVersion & @CRLF)

;~ Ctrl+Q to uncomment below
;~  ;~ Remove KMS Host
;~  RunWait(@ComSpec & ' /C ' & @WindowsDir & '\System32\CScript.exe "' & $g_sMSO_FilePath & '\ospp.vbs" /REMHST', "", @SW_HIDE)
;~  ;~ Configure KMS Host Name
;~  RunWait(@ComSpec & ' /C ' & @WindowsDir & '\System32\CScript.exe "' & $g_sMSO_FilePath & '\ospp.vbs" /SETHST:$g_sKMS_HostName$', "", @SW_HIDE)
;~  ;~ Configure KMS Host Port
;~  RunWait(@ComSpec & ' /C ' & @WindowsDir & '\System32\CScript.exe "' & $g_sMSO_FilePath & '\ospp.vbs" /SETPRT:$g_sKMS_PortName$', "", @SW_HIDE)
;~  ;~ Activate Office
;~  RunWait(@ComSpec & ' /C ' & @WindowsDir & '\System32\CScript.exe "' & $g_sMSO_FilePath & '\ospp.vbs" /ACT', "", @SW_HIDE)

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...