Спрашивающий
Не выполняется скрипт

Вопрос
-
День добрый , есть задача в конвертации *.DOC(X) файлов в *.PDF, выполняется это в конечном итоге с помощью VBS скрипта , но на одном из серверов конвертация не проходит, конвктор закрывается с ошибкой. Прошу подсказать что может мешать 1. Временные файлы создаются 2. Скрипты прикладываю 3. При ручном выполнении скрипта приходит ошибка ? /* Line: 77 Char: 1 Error: Subscript out of rage Code: 800A0009 Source: Microsoft VBScript runtime error */ /* --Сам скрипт Const WdDoNotSaveChanges = 0 Const WdExportFormatPDF = 17 Const MagicFormatPDFA = 999 Dim arguments Set arguments = WScript.Arguments ' Transforms a file using MS Word into the given format. Function ConvertFile( inputFile, outputFile, formatEnumeration ) Dim fileSystemObject Dim wordApplication Dim wordDocument ' Get the running instance of MS Word. If Word is not running, exit the conversion. On Error Resume Next Set wordApplication = GetObject(, "Word.Application") If Err <> 0 Then WScript.Quit -6 End If On Error GoTo 0 ' Find the source file on the file system. Set fileSystemObject = CreateObject("Scripting.FileSystemObject") inputFile = fileSystemObject.GetAbsolutePathName(inputFile) ' Convert the source file only if it exists. If fileSystemObject.FileExists(inputFile) Then ' Attempt to open the source document. On Error Resume Next Set wordDocument = wordApplication.Documents.Open(inputFile, _ False, _ True, _ False) If Err <> 0 Then WScript.Quit -2 End If On Error GoTo 0 On Error Resume Next If formatEnumeration = MagicFormatPDFA Then wordDocument.ExportAsFixedFormat outputFile, _ WdExportFormatPDF, _ False, _ , , , , , , , , , , _ True Else wordDocument.SaveAs outputFile, formatEnumeration End If ' Close the source document. wordDocument.Close WdDoNotSaveChanges If Err <> 0 Then WScript.Quit -3 End If On Error GoTo 0 ' Signal that the conversion was successful. WScript.Quit 2 Else ' Files does not exist, could not convert WScript.Quit -4 End If End Function ' Execute the script. Call ConvertFile( WScript.Arguments.Unnamed.Item(0), WScript.Arguments.Unnamed.Item(1), CInt(WScript.Arguments.Unnamed.Item(2)) ) */
11 ноября 2019 г. 7:15
Все ответы
-
линия 77 это какая? о какой версии офиса идет речь? возможно в этой версии офиса нет функциональной возможности сохранить в пдф
если это работает на одном хосте, то на нем и проводите все необходимые вам конвертирования
The opinion expressed by me is not an official position of Microsoft
12 ноября 2019 г. 17:21Модератор -
77 линия
Call ConvertFile( WScript.Arguments.Unnamed.Item(0), WScript.Arguments.Unnamed.Item(1), CInt(WScript.Arguments.Unnamed.Item(2)) )
офис 2013 сохраняет.На изначальном хосте нет возможности.
14 ноября 2019 г. 7:49 -
77 линия
Call ConvertFile( WScript.Arguments.Unnamed.Item(0), WScript.Arguments.Unnamed.Item(1), CInt(WScript.Arguments.Unnamed.Item(2)) )
офис 2013 сохраняет.На изначальном хосте нет возможности.
как тогда вы знаете что скрипт рабочий?
вы руками можете пересохранить документ как pdf в этой версии офиса?
The opinion expressed by me is not an official position of Microsoft
14 ноября 2019 г. 8:21Модератор -
Так что на другой сборке этот же алгоритм работает на ура.
Да сохраняется.
14 ноября 2019 г. 8:38 -
вы к ком обьекту (его свойствам) обращаетесь по номерам при этом номера от сборки к сборке могут отличаться, как и их названия впрочем и наличие. Если вы знаете на какой сборке скрипт запускается "на ура" используйте эту сборку для ваших конвертаций
The opinion expressed by me is not an official position of Microsoft
14 ноября 2019 г. 8:52Модератор -
ID одинаковые {00020906-0000-0000-C000-000000000046}
OS разные на 2008r2 работает на 2016 standart нет14 ноября 2019 г. 9:37 -
уберите обертку функции (она используется аж 1 раз) и получите конкретною строку проблемы
если не поможет включите visability для приложения и посмотрите глазами возможно вылазит диалоговое окно какое или документ открывается не до конца
вы уверенны что все аргументы передаются корректно?
я бы попробовал перед выполнением функции записать аргументы в файл, а потом в самой функции добавить дозапись контрольных точек
The opinion expressed by me is not an official position of Microsoft
- Изменено Vector BCOModerator 14 ноября 2019 г. 10:31
14 ноября 2019 г. 10:28Модератор -
Спасибо , в этому есть трудности в силу не знания принципов работы всех этих скриптов, буду читать мануалы)) Но направление уже есть)14 ноября 2019 г. 11:22
-
Спасибо , в этому есть трудности в силу не знания принципов работы всех этих скриптов, буду читать мануалы)) Но направление уже есть)
Const WdDoNotSaveChanges = 0 Const WdExportFormatPDF = 17 Const MagicFormatPDFA = 999 Dim arguments Set arguments = WScript.Arguments ' Transforms a file using MS Word into the given format. ' Function ConvertFile( inputFile, outputFile, formatEnumeration ) Dim inputFile Set inputFile = WScript.Arguments.Unnamed.Item(0) Dim outputFile Set outputFile = WScript.Arguments.Unnamed.Item(1) Dim formatEnumeration Set formatEnumeration = CInt(WScript.Arguments.Unnamed.Item(2)) Dim fileSystemObject Dim wordApplication Dim wordDocument ' Get the running instance of MS Word. If Word is not running, exit the conversion. On Error Resume Next Set wordApplication = GetObject(, "Word.Application") If Err <> 0 Then WScript.Quit -6 End If On Error GoTo 0 ' Find the source file on the file system. Set fileSystemObject = CreateObject("Scripting.FileSystemObject") inputFile = fileSystemObject.GetAbsolutePathName(inputFile) ' Convert the source file only if it exists. If fileSystemObject.FileExists(inputFile) Then ' Attempt to open the source document. On Error Resume Next Set wordDocument = wordApplication.Documents.Open(inputFile, _ False, _ True, _ False) If Err <> 0 Then WScript.Quit -2 End If On Error GoTo 0 On Error Resume Next If formatEnumeration = MagicFormatPDFA Then wordDocument.ExportAsFixedFormat outputFile, _ WdExportFormatPDF, _ False, _ , , , , , , , , , , _ True Else wordDocument.SaveAs outputFile, formatEnumeration End If ' Close the source document. wordDocument.Close WdDoNotSaveChanges If Err <> 0 Then WScript.Quit -3 End If On Error GoTo 0 ' Signal that the conversion was successful. WScript.Quit 2 Else ' Files does not exist, could not convert WScript.Quit -4 End If 'End Function ' Execute the script. 'Call ConvertFile( WScript.Arguments.Unnamed.Item(0), WScript.Arguments.Unnamed.Item(1), CInt(WScript.Arguments.Unnamed.Item(2)) )
The opinion expressed by me is not an official position of Microsoft
14 ноября 2019 г. 14:08Модератор