[VBScript] automated printing
dj-julio
-
lallo -
lallo -
Hello,
I need to develop a script that automatically prints a file to a PDF printer.
This script will be launched by PHP .. (is that possible)
I need the script parameters to include the name of the file to print and its destination directory.
For now I have this:
Dim WordApp, Doc Set WordApp = CreateObject("Word.Application") 'Here we define the printer that will be used. WordApp.ActivePrinter="fichier" Set Doc = WordApp.documents.open(fichier) Doc.PrintOut Doc.Close WordApp.Quit
Thanks in advance for your help.
2 answers
I’m working on the same thing. For now I have a script imp.vbs with:
if Wscript.arguments.count > 0 then
Dim WordApp, Doc
Set WordApp = CreateObject("Word.Application")
Set Doc = WordApp.documents.open(Wscript.arguments.Item(0))
Doc.PrintOut 0
Doc.Close
WordApp.Quit
end if
to trigger printing, I run it from the command line:
imp.vbs c:\test.rtf
(I’m working with RTF files which are easier to modify in PHP).
In theory, from PHP you should be able to launch it with
exec('imp.vbs c:\test.rtf').
But when Apache runs as a service (in my case with Wamp) it doesn’t work. I’ve tried lots of things with the service settings but nothing helps. The only working method at the moment is to run Apache in user mode. Not great for a server.
And on your side, did you find anything?
if Wscript.arguments.count > 0 then
Dim WordApp, Doc
Set WordApp = CreateObject("Word.Application")
Set Doc = WordApp.documents.open(Wscript.arguments.Item(0))
Doc.PrintOut 0
Doc.Close
WordApp.Quit
end if
to trigger printing, I run it from the command line:
imp.vbs c:\test.rtf
(I’m working with RTF files which are easier to modify in PHP).
In theory, from PHP you should be able to launch it with
exec('imp.vbs c:\test.rtf').
But when Apache runs as a service (in my case with Wamp) it doesn’t work. I’ve tried lots of things with the service settings but nothing helps. The only working method at the moment is to run Apache in user mode. Not great for a server.
And on your side, did you find anything?
Hello everyone, I understand this topic is old but it sparked me to write my code. I should note that I am a VBScript beginner.
I would like to set up code that allows me to:
1. open a dialog asking "is the month entirely elapsed?" This will offer two options: no and exit the procedure, or yes and run the following procedure:
1.1. I have a chart in an Excel file (grap1.feuille1.xls)
1.2. I want to fetch this chart with a command
1.3. I want to select the CutePDF printer to print the chart
1.4. I want to save the resulting PDF of the print in a specific directory (c:/repertoire-specifique)
I haven't done step 1
For step 1.1 I mostly took the sheet (feuille.xls) because I don't know how to give the graph's address
Step 1.2 I think it's fine
Step 1.3 returns an error (xlApp.ActivePrinter="CutePDF Writer") I don't know why
Step 1.4, I'm thinking about it (a proposal would be welcome)
My code:
Dim xlapp, classeur, feuille, Doc
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = True
Set classeur = xlapp.Workbooks.add
Set feuille = xlapp.ActiveSheet
'point 1.1
Set Doc = xlApp.WorkBooks.open("C:\Documents and Settings\stagiaire\Bureau\feuille.xls")
Ici on définit l'imprimante qui sera utilisée.
xlApp.ActivePrinter="CutePDF Writer"
Doc.PrintOut
Doc.Close
I would like to set up code that allows me to:
1. open a dialog asking "is the month entirely elapsed?" This will offer two options: no and exit the procedure, or yes and run the following procedure:
1.1. I have a chart in an Excel file (grap1.feuille1.xls)
1.2. I want to fetch this chart with a command
1.3. I want to select the CutePDF printer to print the chart
1.4. I want to save the resulting PDF of the print in a specific directory (c:/repertoire-specifique)
I haven't done step 1
For step 1.1 I mostly took the sheet (feuille.xls) because I don't know how to give the graph's address
Step 1.2 I think it's fine
Step 1.3 returns an error (xlApp.ActivePrinter="CutePDF Writer") I don't know why
Step 1.4, I'm thinking about it (a proposal would be welcome)
My code:
Dim xlapp, classeur, feuille, Doc
Set xlapp = CreateObject("Excel.Application")
xlapp.Visible = True
Set classeur = xlapp.Workbooks.add
Set feuille = xlapp.ActiveSheet
'point 1.1
Set Doc = xlApp.WorkBooks.open("C:\Documents and Settings\stagiaire\Bureau\feuille.xls")
Ici on définit l'imprimante qui sera utilisée.
xlApp.ActivePrinter="CutePDF Writer"
Doc.PrintOut
Doc.Close
Hello,
I’m looking for a macro that would allow me, from an Excel file, to create a PDF (Pdf Creator),
The PDF file name would be a concatenation of cell A1; "-" ; B1 from the printed sheet.
The PDF file should always be sent to the same directory, e.g.: "folder1".
I would like the PDF file to remain open for viewing and be closed manually.
Is this possible?
Thanks in advance for any guidance.