1

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
TylerH
  • 20,799
  • 66
  • 75
  • 101
sKhan
  • 29
  • 1
  • 4
  • Is this similar to: https://stackoverflow.com/questions/26420003/batch-file-runs-manually-but-not-in-task-scheduler? You have to be very careful about slashes and quotes, and putting arguments in the right place. – doctorlove Jan 10 '19 at 15:36
  • Thanks for the input, I'm not sure what to modify with the arguments but I tested with these in task scheduler: Start a Program: C:\Windows\System32\wscript.exe Arguments: c:\mypath\RunMacroUploadAsia.vbs Start in: C:\Windows\System32 and run it and it keeps running indefinitely...... Am I doing it right? – sKhan Jan 10 '19 at 21:10

1 Answers1

0

I was running a task that for some reason stopped working and was generating this error. I realised that I had ticked "run with the highest privileges". Once I unticked the box it started working fine again.

TylerH
  • 20,799
  • 66
  • 75
  • 101
newbie
  • 1