简体   繁体   中英

How to fix "Run time error 429: ActiveX Component Can't Create Object" Error when using Task Scheduler to run a selenium vba macro in Excel?

I have a macro in Excel that uses Selenium Basic Type Library to open chrome and automate a few web tasks in Chrome browser. I set up a VBS to run the macro and it runs smoothly manually when I double click the VBS.

Here's the flow:
Task Scheduler -> RunMacroUploadAsia.vbs to start WeekendNoRunAsia macro in WeeklyUpload.xlsm -> Complete WeekendNoRunAsia macro and start UploadPostAsia macro to open chrome browser to perform a few web tasks.

When I use Windows Task Scheduler to run the VBS script to run the Excel macro on a schedule, the

"Run time error 429, ActiveX component can't create object"

error comes up on the Excel window. When I debug the macro it gets stuck in this line of code in the UploadPostAsia macro:

Set D = New ChromeDriver

Why does the VBS runs fine manually and not on Task Scheduler?

Here's the set up of my situation. The VBA is written in Excel 2007 and I have Selenium Type Library installed (SeleniumBasic v2.0.9.0). My laptop is run on Windows 7 Home Basic 64 bit and my Chrome browser v71.0.3578.98.

  1. In Task Scheduler Under Actions tab, I have the following:
    "C:\\Users\\SKhany\\Google Drive\\myexample\\mystuff tasks\\RunMacroUploadAsia.vbs"

  2. Here's the RunMacroUploadAsia.vbs script:

     Option Explicit On Error Resume Next ExcelMacroExample Sub ExcelMacroExample() Dim xlApp Dim xlBook Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlBook = xlApp.Workbooks.Open("C:\\Users\\SKhany\\Google Drive\\myexample\\mystuff tasks\\WeekdayUpload.xlsm", 0, True) xlApp.Run "WeekendNoRunAsia" xlApp.Quit Set xlBook = Nothing Set xlApp = Nothing End Sub
  3. Then the macro WeekendNoRunAsia will run follows by UploadPostAsia (code is as below) and then Task Scheduler will stuck at

    Set D = New ChromeDriver

The workflow works if I don't use Task Scheduler and I tried changing the code to Set D = New Selenium.Chromedriver and still have the same error. I need to run this workflows every weekday and will really like to fix the issue with Task Scheduler or if there's any other way to schedule the VBS is welcome. Appreciate any help you on this.

Public Sub UploadPostAsia()
    Dim ws As Worksheet
    Dim D As WebDriver
    Dim i As Integer

    Set ws = ThisWorkbook.Worksheets("Data")
    Set D = New ChromeDriver
    Const URL = "https://www.myexample.com/login/"

    'To login to website

    With D
        .Start "Chrome"
        .Window.Maximize
        .Get URL
        .FindElementById("user_login").SendKeys(ws.Cells(2, 1)).Click
        .FindElementById("user_pass").SendKeys(ws.Cells(2, 2)).Click
        .FindElementByName("submit").Click
    End With

   'Perform some web tasks
End Sub

I know that this thread is old, but I thought I would add a comment about what I found. I was running a task that for some reason stopped working and was generating this error. After getting really frustrated and playing around for a while I realised that I had ticked "run with the highest privileges". Once I unticked the box it started working fine again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM