1

I try to write a piece of code with VB script to open an excel file, take a print screen and send it by email.

This is on my professional laptop and I have several plugin installed on excel. The excel file in question has a macro inside which run on each opening but does nothing fancy (mostly formatting data).

When I open the workbook normally, everything works fine. When I launch the VB script, I have a error with a missing xla file (refer to file attached)

The code is quite simple:

 Dim Xl 'as Excel.Application\par
 Dim wk 'as Excel.workbook\par
 set Xl = createobject("Excel.application")
 Xl.Visible = True
 Xl.enableevents = True
 set Wk = Xl.workbooks.open("XXX")

enter image description here

1 Answer 1

0

Try to open workbook via shell:

Option Explicit

Dim oExcelApp, oWorkbook

CreateObject("Shell.Application").ShellExecute "C:\Test\Test.xlsm"
Do
    On Error Resume Next
    Set oExcelApp = GetObject(, "Excel.Application")
    WScript.Sleep 5
Loop While Err
On Error Goto 0
Set oWorkbook = oExcelApp.Workbooks("Test.xlsm")
oWorkbook.Sheets(1).Cells(1, 1).Value = Now()
Sign up to request clarification or add additional context in comments.

1 Comment

THank you, the issue is still the same. Apparently it's well know that the addin are not loaded in the same time when launched with VBS and I don't have a workaround as it's a company laptop. My only solution is to disable the addin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.