-
Notifications
You must be signed in to change notification settings - Fork 0
/
Excel Export to PDF.vbs
43 lines (30 loc) · 1.03 KB
/
Excel Export to PDF.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'To run this script use:
'wscript|cscript.exe "<FilePathToScript>\Export Word to PDF.vbs" "<filePathToDoc>.docx"
' Check if the command-line arguments are provided
If WScript.Arguments.Count <> 1 Then
WScript.Echo "Please provide the path to the Word document as an argument."
WScript.Quit 1
End If
'MsgBox "Argument text: " &WScript.Arguments(0)
' Get the path to the Word document from the command-line argument
Dim docPath
docPath = WScript.Arguments(0)
Dim objWord, objDoc
' Create an instance of Word application
Set objWord = CreateObject("Word.Application")
' Hide Word application window
objWord.Visible = False
' Open the Word document
Set objDoc = objWord.Documents.Open(docPath)
' Output PDF path
Dim pdfPath
pdfPath = Replace(docPath,".docx","")
' Export the document as PDF
objDoc.ExportAsFixedFormat pdfPath & ".pdf", 17 ' 17 represents the PDF format
' Close the Word document
objDoc.Close False
' Quit the Word application
objWord.Quit
' Release the objects from memory
Set objDoc = Nothing
Set objWord = Nothing