Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: Script re-write (help!) Thank you so much!

HTVi
TV Discussion Newsgroups

Script re-write (help!) Thank you so much!
John Chen [ at ] NTS 4/16/2007 6:30:05 PM
Can someone take a look the following script and change it to apply for MS
Excel?

'
' Description
' ===========
' Command line conversion of MS Word files to PDF using Click to Convert.
'
' Version: 5.2 of Click to Convert or later
' (C)Copyright 2004 Inzone Software Limited.
'
' Usage
' =====
' Run this script using Windows Scripting or from the Windows command line.
You'll need to have the Microsoft scripting engine installed.
' C:> cscript doc2pdf.vbs <full path to MS Word document>
' E.g. cscript doc2pdf.vbs c:\temp\abc.pdf
'
' You-do:
' =======
' 1. You'll need to add error handling etc for a real world implementation.
' 2. If you plan to run this script many times, you'll need to add code to
wait for the first conversion to complete before beginning the next one.
'


Dim arguments
Set arguments = WScript.Arguments


Function ConvertDocToPDF()

Dim sPath
Dim sInstallPath
Dim oWS
Dim sCurrentPrinter
Dim oWord
Dim oDoc

On Error Resume Next

If arguments.Count < 1 Then
WScript.Echo "Convert a MS Word document to PDF using Click to Convert."
WScript.Echo ""
WScript.Echo "Usage: doc2pdf.vbs <doc-file>"
WScript.Echo "E.g. doc2pdf.vbs c:\temp\myfile.doc"
WScript.Echo ""
WScript.Quit 1
End If

Set oWS = CreateObject("WScript.Shell")

' Access the Registry to retrieve the installation path of Click to Convert.
sInstallPath = oWS.RegRead("HKLM\SOFTWARE\Inzone
Software\ClickToConvert2\Root")
If sInstallPath = vbEmpty Then
WScript.Echo "Click to Convert is not installed correctly"
WScript.Quit 1
End If
sInstallPath = sInstallPath + "\Output\"

' Access the Registry and set the conversion settings.
oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
Convert\CreateHTML", 0, "REG_DWORD"
oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
Convert\CreatePDF", 1, "REG_DWORD"
oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
Convert\HTMLOutputPath", "", "REG_SZ"
oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
Convert\OpenHTML", 0, "REG_DWORD"
oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
Convert\OpenPDF", 1, "REG_DWORD"
oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
Convert\PDFFilename", "", "REG_SZ"
oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
Convert\ShowProgressUI", 1, "REG_DWORD"
oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
Convert\ShowUI", 0, "REG_DWORD"

sPath = arguments.Unnamed.Item(0)
WScript.Echo "MS Word file: " + sPath
WScript.Echo "PDF file: OriginalFileName.pdf, located in the following
folder: " + sInstallPath

' Create the MS Word automation object.
Set oWord = CreateObject("Word.Application")
oWord.Visible = True

' Remember the existing printer so we can reset it.
sCurrentPrinter = oWord.ActivePrinter
oWord.ActivePrinter = "Click to Convert II"

' Open the MS Word document and print it to the Click to Convert printer.
Set oDoc = oWord.Documents.Open(CStr(sPath))
oDoc.PrintOut False

' Close the MS Word document and don't save changes - then
' we also reset the printer back and close MS Word without
' saving any changes.
oDoc.Close False
oWord.ActivePrinter = sCurrentPrinter
oWord.Quit False
Set oWord = Nothing

End Function



Call ConvertDocToPDF()



RE: Script re-write (help!) Thank you so much!
J Ford 4/17/2007 2:16:05 PM
I think you would just change the creation of the WORD object to that of EXCEL

Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
Set oDoc = oExcel.Workbooks.Open(CStr(sPath))
oDoc.PrintOut False
oDoc.Close False
oExcel.ActivePrinter = sCurrentPrinter
oExcel.Quit False

I might be missing a couple items, but you get the jist...

"John Chen [ at ] NTS" wrote:

[Quoted Text]
> Can someone take a look the following script and change it to apply for MS
> Excel?
>
> '
> ' Description
> ' ===========
> ' Command line conversion of MS Word files to PDF using Click to Convert.
> '
> ' Version: 5.2 of Click to Convert or later
> ' (C)Copyright 2004 Inzone Software Limited.
> '
> ' Usage
> ' =====
> ' Run this script using Windows Scripting or from the Windows command line.
> You'll need to have the Microsoft scripting engine installed.
> ' C:> cscript doc2pdf.vbs <full path to MS Word document>
> ' E.g. cscript doc2pdf.vbs c:\temp\abc.pdf
> '
> ' You-do:
> ' =======
> ' 1. You'll need to add error handling etc for a real world implementation.
> ' 2. If you plan to run this script many times, you'll need to add code to
> wait for the first conversion to complete before beginning the next one.
> '
>
>
> Dim arguments
> Set arguments = WScript.Arguments
>
>
> Function ConvertDocToPDF()
>
> Dim sPath
> Dim sInstallPath
> Dim oWS
> Dim sCurrentPrinter
> Dim oWord
> Dim oDoc
>
> On Error Resume Next
>
> If arguments.Count < 1 Then
> WScript.Echo "Convert a MS Word document to PDF using Click to Convert."
> WScript.Echo ""
> WScript.Echo "Usage: doc2pdf.vbs <doc-file>"
> WScript.Echo "E.g. doc2pdf.vbs c:\temp\myfile.doc"
> WScript.Echo ""
> WScript.Quit 1
> End If
>
> Set oWS = CreateObject("WScript.Shell")
>
> ' Access the Registry to retrieve the installation path of Click to Convert.
> sInstallPath = oWS.RegRead("HKLM\SOFTWARE\Inzone
> Software\ClickToConvert2\Root")
> If sInstallPath = vbEmpty Then
> WScript.Echo "Click to Convert is not installed correctly"
> WScript.Quit 1
> End If
> sInstallPath = sInstallPath + "\Output\"
>
> ' Access the Registry and set the conversion settings.
> oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
> Convert\CreateHTML", 0, "REG_DWORD"
> oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
> Convert\CreatePDF", 1, "REG_DWORD"
> oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
> Convert\HTMLOutputPath", "", "REG_SZ"
> oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
> Convert\OpenHTML", 0, "REG_DWORD"
> oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
> Convert\OpenPDF", 1, "REG_DWORD"
> oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
> Convert\PDFFilename", "", "REG_SZ"
> oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
> Convert\ShowProgressUI", 1, "REG_DWORD"
> oWS.RegWrite "HKEY_CURRENT_USER\Software\Inzone Software\Click to
> Convert\ShowUI", 0, "REG_DWORD"
>
> sPath = arguments.Unnamed.Item(0)
> WScript.Echo "MS Word file: " + sPath
> WScript.Echo "PDF file: OriginalFileName.pdf, located in the following
> folder: " + sInstallPath
>
> ' Create the MS Word automation object.
> Set oWord = CreateObject("Word.Application")
> oWord.Visible = True
>
> ' Remember the existing printer so we can reset it.
> sCurrentPrinter = oWord.ActivePrinter
> oWord.ActivePrinter = "Click to Convert II"
>
> ' Open the MS Word document and print it to the Click to Convert printer.
> Set oDoc = oWord.Documents.Open(CStr(sPath))
> oDoc.PrintOut False
>
> ' Close the MS Word document and don't save changes - then
> ' we also reset the printer back and close MS Word without
> ' saving any changes.
> oDoc.Close False
> oWord.ActivePrinter = sCurrentPrinter
> oWord.Quit False
> Set oWord = Nothing
>
> End Function
>
>
>
> Call ConvertDocToPDF()
>
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen