0

I do not understand why there is this error in my VBScript:

'Déclaration des variables
Dim objExcel, objWorkbook, CurrAddin
'Création des Objets
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

For Each CurrAddin In objExcel.AddIns
    If CurrAddin.Installed Then
        CurrAddin.Installed = False
        CurrAddin.Installed = True
    End If
Next CurrAddin

Set objWorkbook = objExcel.Workbooks.Open("C:\rd\python_scripts\private_bank_mini3.xlsx")
'Set objWorkbook = objExcel.Workbooks.Open("C:\rd\python_scripts\Test.xlsx")

'Pause de 10 secondes
WScript.Sleep 10000
'Pause de 8 heures
'WScript.Sleep 28800000

'Enregistrement
objExcel.EnableEvents = False
objWorkbook.Close False
objExcel.EnableEvents = True

'Fermeture de Excel
'objExcel.Quit

'Désallocation mémoire 
Set objExcel = Nothing
Set objWorkbook = Nothing

'Fermeture du Script
WScript.Quit

Please find below my error messages:

Error message1

My script works with the file "Test.xlsx" but not with the "private_bank_mini3.xlsx", the difference between those is the charging of a Add-In at the opening of the second file.

Have you got an idea to manage it please?

Cocalero
  • 13
  • 4
  • which line does the error appear on? you can step through your code by pressing the F8 key – mojo3340 Nov 23 '16 at 09:11
  • 3
    Set objWorkbooks2 = WScript.GetObject("C:\rd\python_scripts\private_bank_mini3.xlsx") , needs fully qualified path name of the file that contains the object persisted to disk. – tsolina Nov 23 '16 at 09:40
  • 2
    but why do you need those pauses?? process is synchronous, workbook.open wont start executing until previous one, objExcel.EnableEvents = False, is finished anyway... – tsolina Nov 23 '16 at 09:45
  • Sorry but I don't understand your comment tsolina: "needs fully qualified path name of the file that contains the object persisted to disk" – Cocalero Nov 23 '16 at 10:35
  • instead "private_bank_mini3.xlsx" this "C:\rd\python_scripts\private_bank_mini3.xlsx", so complete path – tsolina Nov 23 '16 at 10:49
  • Sorry, so according you this following line is wrong ? Set objWorkbook1 = objExcel.Workbooks.Open("C:\rd\python_scripts\private_bank_mini3.xlsx") – Cocalero Nov 23 '16 at 10:55
  • No, @tsolina is saying that the `Set objWorkbooks2 = WScript.GetObject("private_bank_mini3.xlsx")` is wrong – Victor Moraes Nov 23 '16 at 10:56
  • But my problem is with the Open function: Set objWorkbook1 = objExcel.Workbooks.Open("C:\rd\python_scripts\private_bank_mini3.xlsx") – Cocalero Nov 23 '16 at 10:59
  • Try to create a file with only the lines up to the `Set objWorkbook1 = objExcel.Workbooks.Open("C:\rd\python_scripts\private_bank_m‌​ini3.xlsx")`. See if it works or you still get an error. Your code works just fine on my end – Victor Moraes Nov 23 '16 at 11:11
  • can you open that document manually? – tsolina Nov 23 '16 at 11:16
  • Yes, but my file charge an Add-in and I think this is the problem. Because this code works with a file that doesn't use this Add-In. How can I manage it please ? – Cocalero Nov 23 '16 at 11:22
  • Which add-in does it trigger? – Victor Moraes Nov 23 '16 at 11:24
  • 4
    @VictorMoraes Doesn't matter. Add-ins must be loaded explicitly when instantiating Excel from a script. Possible duplicate of [Loading addins when Excel is instantiated programmatically](http://stackoverflow.com/q/213375/1630171). – Ansgar Wiechers Nov 23 '16 at 11:26
  • Thank you. So in this case, how can we do this in VB Script please ? – Cocalero Nov 23 '16 at 11:31
  • @AnsgarWiechers thanks for the info, I've never had to load add-ins in Excel, so it is good to know that. Sebastian, Ansgar has provided a link with the answer to your question :) – Victor Moraes Nov 23 '16 at 12:15
  • Yes, but I am still confuse because the response a VBA script and I don't know how can I put it in my VBScript – Cocalero Nov 23 '16 at 12:31
  • Instead of the (implicit) `Application` object that you have in VBA use your (explicit) application object variable (`objExcel`) in VBScript. – Ansgar Wiechers Nov 23 '16 at 13:12
  • I have update my code, but I don't understand how manage it – Cocalero Nov 23 '16 at 13:24
  • 1
    I think this is wrong (line 12): `Next CurrAddin`. Comment out or otherwise remove the `CurrAddin` – oracle certified professional Nov 23 '16 at 15:04

0 Answers0