D
D
dmitriev_romka2020-05-06 19:06:32
excel
dmitriev_romka, 2020-05-06 19:06:32

How to fix an error when starting a vbs file with the Task Scheduler?

I run the vbs file through the scheduler on windows 10. Vbs without the scheduler opens everything perfectly, opening the file with it gives the following error:

Failed to get property "getScrollTop" of a link whose value is undefined or NULL


Please tell me what is wrong, what he does not like and how to fix it?

I saved additional information about the error in a notepad, I can’t attach a file here, if necessary I can send the

VBS macro to the mail:
Call Run_macros

  'запуск макроса'
Sub Run_macros()
  'запускаем Excel-процесс
set objExcel = CreateObject ("Excel.Application")
objExcel.Visible = true    
Op_writ="R:\ЭКСЕЛЬ\файл1"
objExcel.Workbooks.Open (Op_writ)
  'запуск макроса
objExcel.run "ОБН_данных"
  'сохранение файла
objExcel.Workbooks("файл1.xlsm").Save
  'по завершению закрываем документ. Пишем только имя файла, без пути
objExcel.Workbooks("файл1.xlsm").Close(false)
  'закрываем Excel-процесс
objExcel.Quit
end sub

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2020-05-12
@dmitriev_romka

In the process of correspondence (in the next answer) and experimentally, it turned out that the reason for the incorrect work was the "phantom" Excel process that remained in memory and did not end after the script was executed. Therefore the error also was shown from the second time of execution.
the probable reason that the process remained hanging is that the script is not correct in some way.
Apparently, some object remains in memory, which prevents the Excel process from completing correctly.
There are two solutions:
1) try to make the correct script. This is correct, but cold.
The last option is attached, but it still did not work correctly.

spoiler

Call Run_macros

Sub Run_macros()

    Dim objExcel
    Dim Op_writ
    Dim Wb
    
   'запускаем Excel-процесс
    Set objExcel = CreateObject ("Excel.Application")
    objExcel.Visible = true    
    Op_writ="R:\инста\ЭКСЕЛЬ\АНАЛИЗ\НОВЫЙПОДПИСЧИКИ17"
    Set Wb = objExcel.Workbooks.Open (Op_writ)
   'запуск макроса
   objExcel.run "ОБН_данных"
   'сохранение файла
   objExcel.Workbooks("НОВЫЙПОДПИСЧИКИ17.xlsm").Save
   'по завершению закрываем документ. Пишем только имя файла, без пути
   objExcel.Workbooks("НОВЫЙПОДПИСЧИКИ17.xlsm").Close(false)
   'закрываем Excel-процесс
  objExcel.Quit
  Set objExcel = Nothing 
  Set Wb = Nothing
End Sub

2) "kill" the process with a script. simple, reliable, but it's like a crutch. Although judging by the Internet, a number of people who have encountered this problem have chosen this path).
A number of explanations about the problem, how to make a correct script, and also how to "kill" the process - follow the links:
https://stackoverflow.com/questions/25147242/excel...
https://stackoverflow.com/questions/26303173/how -c...

A
Alexander, 2020-05-06
@NeiroNx

Most likely, the macro is designed to run in graphical mode and cannot work with an ActiveX component - some of the parameters simply do not exist - hence the error. Rewrite without getScrollTop and the like, or add a pre-execution check. The probable cause is that the scheduler starts in a mode without access to the graphics subsystem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question