{"id":104,"date":"2009-02-17T12:56:00","date_gmt":"2009-02-17T12:56:00","guid":{"rendered":"http:\/\/www.roysac.com\/blog\/wp-admin\/2009\/02\/convert-word-2007-documents-and-upload-to-google-docs\/"},"modified":"2009-02-17T12:56:00","modified_gmt":"2009-02-17T12:56:00","slug":"convert-word-2007-documents-and-upload-to-google-docs","status":"publish","type":"post","link":"http:\/\/www.roysac.com\/blog\/2009\/02\/convert-word-2007-documents-and-upload-to-google-docs\/","title":{"rendered":"Convert Word 2007 Documents and Upload to Google Docs"},"content":{"rendered":"<\/p>\n<p>It started with a script by Michael Suodenjoki called &#8220;docx2pdf.vbs&#8221; that lets you convert individual Word 2007 documents to PDF. It is possible to use it to process a batch of files, such as all documents in a specific directory, by using (programming) another <a href=\"http:\/\/www.madirish.net\/?article=209\" target=\"_blank\">sophisticated MS DOS batch<\/a> script, but that is a pain in the neck itself. I ran into issues, because I had spaces in the file names of the documents that I wanted to convert and I thought to myself that it is probably easier and safer to change the VBScript itself instead of writing another script in a different language. <\/p>\n<p>By the way, for the conversion to PDF format with Microsoft Word 2007 is it necessary that you installed next to Microsoft Office 2007 of course, also the &#8220;<a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyId=F1FC413C-6D89-4F15-991B-63B07BA5F2E5&#038;displaylang=en\" target=\"_blank\">Microsoft Save as PDF<\/a>&#8221; Add-In for 2007 Office, which is available for free download at the Microsoft.com web site <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyId=F1FC413C-6D89-4F15-991B-63B07BA5F2E5&#038;displaylang=en\" target=\"_blank\">here<\/a>.<\/p>\n<h3>Extending the Docx2Pdf Conversion Script<\/h3>\n<p>So I changed the script to allow the processing of a whole folder instead of just one file. While I was doing that, I realized that I need?? a filter to make sure that I only process?? documents that Word 2007 can load. While I was thinking about a solution about that, I realized that a)?? Word 2007 supports more than just Word 2007 .DOCX documents and b) that the Google Docs API only supports Word 97 .DOC documents and not PDF, like the manual uploader in their web interface. Converting my Word 2007 documents to be able to get them up on <a href=\"http:\/\/docs.google.com\/\" target=\"_blank\">Google Docs<\/a> was actually the cause to get me started with all this.<\/p>\n<h3>Google Docs Limitations<\/h3>\n<p>The <a href=\"https:\/\/docs.google.com\/DocAction?action=updoc&#038;hl=en\" target=\"_blank\">Google Docs web uploader<\/a> supports Adobe PDF and Word 97 DOC format for documents, but you have to upload documents one by one manually. That sucks big time and I hope that Google will do something about that soon, but in the mean time there is not much we can do about it. In order to get several documents up on Google Docs quickly, you have to use their API or the create document via Email or Email with Word 97 document attachment features. Adobe PDF is supposed to work with their <a href=\"http:\/\/code.google.com\/apis\/gdata\/\" target=\"_blank\">GData API<\/a> for Google Docs, but I never got <a href=\"http:\/\/code.google.com\/p\/gdata-python-client\/\" target=\"_blank\">those Python scripts<\/a> to work. I was able to connect to Google, <a href=\"http:\/\/code.google.com\/apis\/documents\/docs\/1.0\/developers_guide_python.html#UploadingDocs\" target=\"_blank\">but not to transfer<\/a>&#8230; anyway.<\/p>\n<p>Word 2007 supports the output of documents in numerous formats, including Word 97, HTML, RTS, TXT and PDF, if you installed the free Microsoft PDF Add-on. So I added the option to specify the output format. <\/p>\n<p>Then I was thinking of automation of uploads to Google Docs and realized that I needed an additional filter to avoid that I will ending up sending the same documents to Google over and over again. Thus I added some date filter options based on the creation date and date when the document was last modified.<\/p>\n<p>Last but not least I had to add the option to send the converted documents (that were converted to .DOC format) to Google Docs. The upload via email was the way to go and my script was complete. Here is what came out of all of this.<\/p>\n<h3>Save Word 2007 Documents in a different Format and more <\/h3>\n<pre>Usage: cscript \/nologo doc2pdf.vbs [<input-file>] [\/dir:<input-dir>] <br>[\/date:created\/modified] [\/datefrom:mm-dd-yyyyy] [\/dateto:mm-dd-yyyy] [\/days:nn]<br>[\/f:<output-format>] [\/o:<output-file>] [\/googledocs:<email>] <\/pre>\n<p><\/p>\n<h4>Basic Options:<\/h4>\n<p><\/p>\n<p><strong>\/help<\/strong>???? <br \/>Specifies that this usage\/help information should be displayed. <\/p>\n<p><\/p>\n<p><strong>\/verbose<\/strong> <br \/>Specifies that detailed information about the processing should be displayed. <\/p>\n<p><\/p>\n<h4>Parameters (optional):<\/h4>\n<p><strong>\/dir:<input-dir><\/strong> <br \/>Directory Batch Processing. Use <input-file> argument as filter option (e.g. *.DOCX or *.* for all) <\/p>\n<h5><u>Date Filter Options <\/u><\/h5>\n<p><\/p>\n<p><strong>\/date:created\/modified<\/strong> <br \/>Date filter option (only for batch processing). Specify if the date parameters should apply to either the <br \/>creation date of the file or the date when it was last modified. <\/p>\n<p><\/p>\n<p><strong>\/datefrom:mm-dd-yyy <br \/>\/datetto:mm-dd-yyy<\/strong> <br \/>From and To Date options for that work together with the \/date option. If \/dateto is not provided, then the script will automatically assume today. Alternative to a specific date range is it possible to provide the following parameter <\/p>\n<p><\/p>\n<p><strong>\/days:nn<\/strong> <br \/>&#8220;nn&#8221; stands for a numeric value from 0 to whatever and are the number of days from today, to determine the from date. The value 1 for example would mean yesterday, or files that were created\/changed since yesterday until today. 7 would be a week and so on. <\/p>\n<p><\/p>\n<p><strong><u>Output Options Parameters<\/u><\/strong> <\/p>\n<p><\/p>\n<p><strong>\/f:<format><\/strong> <br \/>Specifies the output format values: DOCX, DOCM, DOTX, DOTM, XML, PDF (default), XPS, TXT, DOS, ASC, HTML, HTM, RTS, DOC, WEB <\/p>\n<p><\/p>\n<p><strong>\/o:<file> <br \/><\/strong>Optionally specification of output file, which only works for single file conversions and not batch processing. <\/p>\n<p><\/p>\n<p><strong><u>Send to Google Docs via Email Option <\/u><\/strong><\/p>\n<p><\/p>\n<p><strong>\/googledocs:<email><\/strong> <\/p>\n<p><\/p>\n<p>Your personal email to upload documents, which looks like: longstring@prod.writely.com <br \/>You can find that email, if you login to your Google Docs account and go to the &#8220;Upload&#8221; screen. <\/p>\n<p><\/p>\n<p>Note: Google Docs only supports the import of documents in DOC file format (Office 97). <br \/>PDF files are not supported. The file size is also limited to 500KB per document. <\/p>\n<p><\/p>\n<h4>Examples:<\/h4>\n<p><\/p>\n<p><strong>1.<\/strong> Convert all Word 2007 documents (.docx) that were modified on or since December 31, 2008 and are located in C:\\DOCS to PDF and show detailed information about the processing. <\/p>\n<pre>cscript \/nologo docx2pdf2.vbs *.docx \/f:PDF \/dir:C:\\DOCS \/date:modified \/datefrom:12-31-2008 \/verbose<\/pre>\n<p><\/p>\n<p><strong>2.<\/strong> Convert all Word 2007 documents (.docx) that where created in the last 7 days and are located in <br \/>C:\\MY DOCUMENTS to Word 97 (.DOC) and send them to Google Docs. <\/p>\n<pre>cscript \/nologo docx2pdf2.vbs *.docx \/f:DOC \/dir:<span>\"C:\\MY DOCUMENTS\"<\/span> \/date:created \/days:7 <br> \/googledocs:mysecretemail@prod.writely.com <\/pre>\n<p><\/p>\n<p><strong>3.<\/strong> Convert a single Word 2007 Document C:\\DOCS\\mydocument.docx to PDF and save it as <br \/>C:\\MY DOCUMENTS\\mynewdocument.pdf <\/p>\n<pre>cscript \/nologo docx2pdf2.vbs <span>\"C:\\DOCS\\mydocument.docx\"<\/span> \/o:<span>\"C:\\MY DOCUMENTS\\mynewdocument.pdf\"<\/span> <\/pre>\n<p><\/p>\n<p><strong>4.<\/strong> Convert C:\\DOCS\\mydocument.docx to HTML and save it in the same folder <\/p>\n<pre>cscript \/nologo docx2pdf2.vbs <span>\"C:\\DOCS\\mydocument.docx\"<\/span> \/f:HTML <\/pre>\n<p><\/p>\n<p><\/p>\n<h3>Notes and Considerations<\/h3>\n<p><\/p>\n<p>The script must be called with <strong><em>CSCRIPT.EXE<\/em><\/strong> instead of <em><strong>WSCRIPT.EXE<\/strong><\/em>, because it makes use of the STDOUT option of <strong><em>VBSCRIPT<\/em><\/strong>. <strong><em>WSCRIPT.EXE<\/em><\/strong> is used by default, if you start a .VBS Visual Script document (e.g. double click or call from a .BAT file).?? Its not the end of the world, if you dont, because the script will re-launch itself?? <br \/>using <strong><em>CSCRIPT<\/em><\/strong>, if you execute it with <strong><em>WSCRIPT<\/em><\/strong> anyway. However that might cause other?? issues, depending how you are using this script.?? For example the redirection of the output into a text file wont work, because?? <br \/>the script opens a new DOS session. I used the proper call of the script in my examples above. The &#8220;<strong><em>\/nologo<\/em><\/strong>&#8221; parameter is not required by the way. I only use it to suppress the Microsoft messages and screens.<\/p>\n<p><\/p>\n<p>There are different ways to send out emails via a script that runs on a users computer, each with their own problems and advantages. I implemented two options into my script. By default is Microsofts CDO used to send out the emails to Google Docs, but I also added the option to use Outlook MAPI instead.<\/p>\n<p><\/p>\n<h3>Using MAPI instead of CDO<\/h3>\n<p><\/p>\n<p>Pretty near the beginning of the script is a line that reads:<\/p>\n<pre>Const EmailSendMethod = 2 1 = MAPI (Outlook), 2 = CDO<\/pre>\n<p><\/p>\n<p><span>To use MAPI instead of CDO, simply change this line to <\/span><\/p>\n<pre>Const EmailSendMethod = 1 1 = MAPI (Outlook), 2 = CDO<\/pre>\n<p><\/p>\n<p>I wanted to go with MAPI first, but the biggest problems that I had were those stupid security messages that popped up every time that I wanted to send one email to Google. Since I do not want to sit in front of the computer to acknowledge dozens or more emails\/documents to be sent, I changed the script to use CDO instead.<\/p>\n<p><\/p>\n<p><a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFMAPISecurity1.png\"><img loading=\"lazy\" decoding=\"async\" height=\"203\" alt=\"DOCX2PDF-MAPI-Security1\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFMAPISecurity1_thumb.png\" width=\"350\" align=\"right\" border=\"0\"><\/a>Here is what I got when I used MAPI. First was this message, which made perfect sense to me, although I missed the option to say &#8220;always allow access for this application&#8221; that it does not come up in the future anymore. <\/p>\n<p><\/p>\n<p>I know that from Skype and it works perfect there, but nothing like it in Microsoft Outlook.<\/p>\n<p><\/p>\n<p>?? <\/p>\n<p><\/p>\n<p>Anyhow, I set the option to &#8220;Allow access for 10 minutes&#8221;, which should have been enough to process a bunch of documents and send them out to Google, but it wasnt to be like that. Instead I got a pop-up every time I created a new Email object. The Message window has the &#8220;Allow&#8221; button disabled for several seconds, before you can approve the email to be created and nothing is done until you pressed &#8220;Allow&#8221;, over and over again.<\/p>\n<p><\/p>\n<h3><a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFMAPISecurity2.png\"><img loading=\"lazy\" decoding=\"async\" height=\"179\" alt=\"DOCX2PDF-MAPI-Security2\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFMAPISecurity2_thumb.png\" width=\"350\" align=\"left\" border=\"0\"><\/a><\/h3>\n<p><\/p>\n<p>If you know how I can tell Outlook 2007 to trust my script that resides locally on the users machine and thus be able to use MAPI to generate email messages automatically, please let me know. I know that you can get something like a &#8220;Trusted Publisher Certificate&#8221;, but hey, I am not a software company who is selling a commercial plug-in to people, not even a compiled program at all. Its plain and pure code that is executed and processed by Windows on the fly, without the need to compile it first.<\/p>\n<p><\/p>\n<h3>CDO Requirements and Troubleshooting<\/h3>\n<p><\/p>\n<p>CDO uses the build-in SMTP server feature that comes with Windows XP (except XP Home). <a href=\"http:\/\/www.blackviper.com\/WinXP\/servicecfg.htm\" target=\"_blank\">It is not installed by default<\/a>. You can install SMTP by going to &#8220;<em><strong>Start\\Control Panel\\Add or Remove Programs<\/strong><\/em>&#8220;. There select on the left the Tab &#8220;<em><strong>Add\/Remove Windows Components<\/strong><\/em>&#8220;. Scroll down to &#8220;<em><strong>Internet Information Services (IIS)<\/strong><\/em>&#8220;, highlight it and press the &#8220;<em><strong>Details<\/strong><\/em>&#8221; button. There you have to enable &#8220;<em><strong>SMTP Service<\/strong><\/em>&#8220;, which will automatically also enable &#8220;<em><strong>Common Files<\/strong><\/em>&#8221; and &#8220;<em><strong>World Wide Web Service<\/strong><\/em>&#8220;, if it was not installed already on your computer either. Press &#8220;<em><strong>Okay<\/strong><\/em>&#8221; to close the &#8220;<em><strong>Details<\/strong><\/em>&#8221; screen and then &#8220;<em><strong>Next<\/strong><\/em>&#8220;. Follow the steps on the screen. You might require your original Windows Installation Disk, so have it handy before you get started with this.<\/p>\n<p><\/p>\n<p>The script will error out, if you do not have SMTP installed on your machine yet!<\/p>\n<p><\/p>\n<p>The nice thing about it is that you dont even require to have an email client installed and running (or ready to run) in order to send out an email from your machine. That is a draw-back as well, because you will dont have a reference or copy of the emails that you sent out. They wont appear in?? the &#8220;<strong><em>Sent<\/em><\/strong>&#8221; folder of MS Outlook, Outlook Express, Live Mail or whatever email client you might be using.<\/p>\n<p><\/p>\n<p><a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOPickupFolder.png\"><img loading=\"lazy\" decoding=\"async\" height=\"260\" alt=\"DOCX2PDF-CDO-PickupFolder\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOPickupFolder_thumb.png\" width=\"700\" border=\"0\"><\/a><\/p>\n<p><\/p>\n<p>If you had SMTP installed on your computer already, but not running (like I did), then the script will run without any errors. It will also say that it sent out the emails to Google, but that is not entirely correct. It created it, yes, but sending them is an entirely different story. If the SMTP service is stopped, no email is being sent. Windows dumps the prepared emails into the &#8220;<strong><em>Pickup<\/em><\/strong>&#8221; folder of &#8220;<em><strong>IIS<\/strong><\/em>&#8220;, which is located by default at &#8220;<em><strong>C:\\Inetpub\\mailroot\\Pickup<\/strong><\/em>&#8220;, unless you configured it to be somewhere else.<\/p>\n<p><\/p>\n<p>Make sure that the SMTP Service is running. To check that and to start the service manually, go to your computers &#8220;<strong><em>Administrative Tools<\/em><\/strong>&#8221; and start &#8220;<strong><em>Services<\/em><\/strong>&#8221; (Administrative Tools are located in the &#8220;<strong><em>Control Panel<\/em><\/strong>&#8220;, like the &#8220;<strong><em>Add or Remove Programs<\/em><\/strong>&#8221; tool). Look for the service with the name &#8220;<strong><em>Simple Mail Transfer Protocol (SMTP)&#8221;<\/em><\/strong>. See the image below for illustration.<\/p>\n<p><\/p>\n<p><a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOSMTPService.png\"><img loading=\"lazy\" decoding=\"async\" height=\"186\" alt=\"DOCX2PDF-CDO-SMTP-Service\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOSMTPService_thumb.png\" width=\"700\" border=\"0\"><\/a> <\/p>\n<p><\/p>\n<p>Double-Click on it and press &#8220;<strong><em>Start<\/em><\/strong>&#8220;, if the status of the service is anything else than &#8220;<strong><em>Started<\/em><\/strong>&#8220;. If it fails to start, then it could be that services where it depends on are not started as well. You can find out by selecting the &#8220;<strong><em>Dependencies<\/em><\/strong>&#8221; tab. Make sure that the services listed there are running as well. <\/p>\n<p><\/p>\n<p><a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOSMTPDependency.png\"><img loading=\"lazy\" decoding=\"async\" height=\"277\" alt=\"DOCX2PDF-CDO-SMTP-Dependency\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOSMTPDependency_thumb.png\" width=\"350\" align=\"left\" border=\"0\"><\/a> <\/p>\n<p><\/p>\n<p>See on the left. It shows that the &#8220;<strong><em>Event Log<\/em><\/strong>&#8221; and &#8220;<strong><em>IIS Admin<\/em><\/strong>&#8221; services need to run that the SMTP service can be started as well.<\/p>\n<p><\/p>\n<p>Once the SMTP service is running, you are ready to rock and roll. If you ran the script and then found out that the service was not running, emails stuck in the &#8220;<strong><em>Pickup<\/em><\/strong>&#8221; folder will not be processed automatically once SMTP is running. Another email must be triggered that SMTP will pick them up and add them to its processing &#8220;<strong><em>Queue<\/em><\/strong>&#8221; folder for sending and then finally send it out to Google.<\/p>\n<p><\/p>\n<p>??<\/p>\n<p><\/p>\n<p><a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOQueue.png\"><img loading=\"lazy\" decoding=\"async\" height=\"277\" alt=\"DOCX2PDF-CDO-Queue\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOQueue_thumb.png\" width=\"700\" border=\"0\"><\/a><\/p>\n<p><\/p>\n<h3>SMTP Service Security (for CDO)<a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOIISSMTP1.png\"><img loading=\"lazy\" decoding=\"async\" height=\"195\" alt=\"DOCX2PDF-CDO-IIS-SMTP1\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOIISSMTP1_thumb.png\" width=\"350\" align=\"right\" border=\"0\"><\/a><\/h3>\n<p><\/p>\n<p>Having the SMTP Service running will upset some anti-virus or anti-spyware programs, because it can become an issue, if it is not secured, detected by hackers and then abused to relay spam message via your computer to other people on the Internet. <\/p>\n<p><\/p>\n<p>You dont to invite trouble, so go and change the security settings that nobody else can use your mail service, except you. <\/p>\n<p><\/p>\n<p><a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOIISSMTP2.png\"><img loading=\"lazy\" decoding=\"async\" height=\"335\" alt=\"DOCX2PDF-CDO-IIS-SMTP2\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOIISSMTP2_thumb.png\" width=\"350\" align=\"right\" border=\"0\"><\/a>Open the IIS manager, which is located under &#8220;<strong><em>Administrative Tools<\/em><\/strong>&#8221; (like the &#8220;<strong><em>Services<\/em><\/strong>&#8221; tool). There you will find the item &#8220;<strong><em>Default SMTP Virtual Service<\/em><\/strong>&#8221; entry on the left. <\/p>\n<p><\/p>\n<p>Highlight it, right-click with your mouse and select &#8220;<strong><em>Properties<\/em><\/strong>&#8220;. Then select the &#8220;<strong><em>Access<\/em><\/strong>&#8221; tab and click on the &#8220;<strong><em>Authentication<\/em><\/strong>&#8221; button. <\/p>\n<p><\/p>\n<p>It is probably set to &#8220;<strong><em>Anonymous Access<\/em><\/strong>&#8220;. Change that to &#8220;<strong><em>Integrated Windows Authentication<\/em><\/strong>&#8220;. <\/p>\n<p><\/p>\n<p>Users that need permissions to use the service can be added via the &#8220;<strong><em>Security<\/em><\/strong>&#8221; tab as needed.<\/p>\n<p><\/p>\n<p>This will take of things and keep your SMTP service on your machine secure.<\/p>\n<p><\/p>\n<h3>Email Delivery Issues with Google Docs<\/h3>\n<p><\/p>\n<p>I use the secret email address for your Google Docs account not only as the TO address of the email, but also as the sender address as well. This has a nice little side effect to it. <\/p>\n<p><\/p>\n<p>Sometimes there are issues with Google Docs and it is unable to process a document that it received via attachment of an email for whatever reason. <\/p>\n<p><\/p>\n<p>If the email delivery fails, a system notification is being sent by the receiving mail server to the sender of the email, your Google Docs upload email address. Since the email upload feature also supports sending a whole text email to be converted to a document, this is what Google Docs is doing with the Error emails that it receives about the original uploads that failed.<a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOGoogleDocs1.png\"><img loading=\"lazy\" decoding=\"async\" height=\"257\" alt=\"DOCX2PDF-CDO-GoogleDocs1\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOGoogleDocs1_thumb.png\" width=\"700\" border=\"0\"><\/a><\/p>\n<p><\/p>\n<p>If you open up such Error Email document, you will be able to find out, which document (file name) that was sent by the script was not uploaded and processed properly. Just send it again with another batch or upload it manually via the web interface, whatever is easier for you.<\/p>\n<p><\/p>\n<p>??<a href=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOGoogleDocs2.png\"><img loading=\"lazy\" decoding=\"async\" height=\"257\" alt=\"DOCX2PDF-CDO-GoogleDocs2\" src=\"http:\/\/www.roysac.com\/blogimages\/DOCX2PDFCDOGoogleDocs2_thumb.png\" width=\"700\" border=\"0\"><\/a> <\/p>\n<p><\/p>\n<h3>The Script and the Source Code Download<\/h3>\n<p><\/p>\n<p>Here is the source code that you can see how the various features were implemented (and to use it for your own tools and scripts hehe). Dont type it off the screen or copy and paste it into a document, if you want to use my script as it is. <a href=\"http:\/\/www.roysac.com\/blogimages\/docx2pdf2.vbs.txt\" target=\"_blank\">You can download the full source of it here<\/a> as a text file. It is called <a href=\"http:\/\/www.roysac.com\/blogimages\/docx2pdf2.vbs.txt\" target=\"_blank\"><strong>docx2pdf2.vbs.txt<\/strong><\/a><strong>.<\/strong> Rename it to remove the .TXT and you are ready to rock and roll.<\/p>\n<p><\/p>\n<p>Thats it! Have Fun!<\/p>\n<p><\/p>\n<p>Carsten aka Roy\/SAC<\/p>\n<p><\/p>\n<div>\n<pre><span>   1:  <\/span><span><\/span><\/pre>\n<pre><span>   2:  <\/span><span> DOC2PDF2.VBS Microsoft Scripting Host Script (Requires Version 5.6 or newer)<\/span><\/pre>\n<pre><span>   3:  <\/span><span> --------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span>   4:  <\/span><span> Author: Carsten Cumbrowski <\/span><\/pre>\n<pre><span>   5:  <\/span><span> Created: December 2008 and February 2009<\/span><\/pre>\n<pre><span>   6:  <\/span><span> <\/span><\/pre>\n<pre><span>   7:  <\/span><span> Based on a script by  Michael Suodenjoki<\/span><\/pre>\n<pre><span>   8:  <\/span><span> This script can create a PDF file from a Word document provided youre using<\/span><\/pre>\n<pre><span>   9:  <\/span><span> Word 2007 and have the Office Add-in: Save As PDF installed.<\/span><\/pre>\n<pre><span>  10:  <\/span><span> It can also save the documents in other formats that are supported by MS Word 2007<\/span><\/pre>\n<pre><span>  11:  <\/span><span> The script allows batch processing of multiple files (e.g. a directory) and also the <\/span><\/pre>\n<pre><span>  12:  <\/span><span> sending via email to Google Docs (output format DOC, Office 97 required) <\/span><\/pre>\n<pre><span>  13:  <\/span><span><\/span><\/pre>\n<pre><span>  14:  <\/span><span> Script must be called with CSCRIPT instead of WSCRIPT<\/span><\/pre>\n<pre><span>  15:  <\/span><span> Its not the end of the world, if you dont, because the script will relaunch itself <\/span><\/pre>\n<pre><span>  16:  <\/span><span> using CSCRIPT, if you execute it with WSCRIPT anyway. However that might cause other<\/span><\/pre>\n<pre><span>  17:  <\/span><span> issues, depending how you are using this script<\/span><\/pre>\n<pre><span>  18:  <\/span><span> For example the redirection of the output into a text file wont work, because <\/span><\/pre>\n<pre><span>  19:  <\/span><span> the script opens a new DOS session<\/span><\/pre>\n<pre><span>  20:  <\/span>??<\/pre>\n<pre><span>  21:  <\/span>ForceCscript <span>true<\/span><\/pre>\n<pre><span>  22:  <\/span><span> Constants<\/span><\/pre>\n<pre><span>  23:  <\/span>??<\/pre>\n<pre><span>  24:  <\/span><span>Const<\/span> iGoogleDocsSizeLimit = 5120000<\/pre>\n<pre><span>  25:  <\/span><span>Const iGoogleDocsReqFormat = 0<\/span><\/pre>\n<pre><span>  26:  <\/span>??<\/pre>\n<pre><span>  27:  <\/span><span>Const<\/span> WdDoNotSaveChanges = 0<\/pre>\n<pre><span>  28:  <\/span><span>Const<\/span> EmailSendMethod = 2   <span>1 = MAPI (Outlook), 2 = CDO<\/span><\/pre>\n<pre><span>  29:  <\/span>??<\/pre>\n<pre><span>  30:  <\/span><span> see WdSaveFormat enumeration constants: <\/span><\/pre>\n<pre><span>  31:  <\/span><span> http:\/\/msdn2.microsoft.com\/en-us\/library\/bb238158.aspx<\/span><\/pre>\n<pre><span>  32:  <\/span><span>Const<\/span> wdFormatPDF = 17  <span> PDF format. <\/span><\/pre>\n<pre><span>  33:  <\/span><span>Const<\/span> wdFormatXPS = 18  <span> XPS format. <\/span><\/pre>\n<pre><span>  34:  <\/span><span>Const<\/span> wdFormatDocument97=0  <span>Word97 Format<\/span><\/pre>\n<pre><span>  35:  <\/span><span>Const<\/span> wdFormatDocumentDefault = 16 <span>Word Default (.DOCX in Word2007)<\/span><\/pre>\n<pre><span>  36:  <\/span>??<\/pre>\n<pre><span>  37:  <\/span><span>Const<\/span> wdFormatWebArchive = 9 <span>Web Archive<\/span><\/pre>\n<pre><span>  38:  <\/span>??<\/pre>\n<pre><span>  39:  <\/span><span>Const<\/span> wdFormatTemplate = 1 <span>Word 97 Template<\/span><\/pre>\n<pre><span>  40:  <\/span>??<\/pre>\n<pre><span>  41:  <\/span><span>Const<\/span> wdFormatRTF = 6 <span>RTF<\/span><\/pre>\n<pre><span>  42:  <\/span>??<\/pre>\n<pre><span>  43:  <\/span><span>Const<\/span> wdFormatHTML = 8 <span>Std HTML<\/span><\/pre>\n<pre><span>  44:  <\/span><span>Const<\/span> wdFormatFilteredHTML = 10 <span>Filtered HTML<\/span><\/pre>\n<pre><span>  45:  <\/span>??<\/pre>\n<pre><span>  46:  <\/span><span>Const<\/span> wdFormatText = 2 <span>Windows Text<\/span><\/pre>\n<pre><span>  47:  <\/span><span>Const<\/span> wdFormatTextLineBreaks = 3 <span>Windows Text with line-breaks preserved<\/span><\/pre>\n<pre><span>  48:  <\/span><span>Const<\/span> wdFormatEncodedText = 7 <span>Encoded Text (Unicode)<\/span><\/pre>\n<pre><span>  49:  <\/span><span>Const<\/span> wdFormatUnicodeText = 7<\/pre>\n<pre><span>  50:  <\/span><span>Const<\/span> wdFormatDOSTextLineBreaks = 5 <span>DOS Text w Line-Breaks<\/span><\/pre>\n<pre><span>  51:  <\/span><span>Const<\/span> wdFormatDOSText = 4 <span>DOS<\/span><\/pre>\n<pre><span>  52:  <\/span>??<\/pre>\n<pre><span>  53:  <\/span>??<\/pre>\n<pre><span>  54:  <\/span><span>Const<\/span> wdFormatXML = 11 <span>XML<\/span><\/pre>\n<pre><span>  55:  <\/span><span>Const<\/span> wdFormatXMLDocument = 12 <span>XML DOc   .docx<\/span><\/pre>\n<pre><span>  56:  <\/span><span>Const<\/span> wdFormatXMLDocumentMacroEnabled = 13 <span>XML Macros Enabled  .docm<\/span><\/pre>\n<pre><span>  57:  <\/span><span>Const<\/span> wdFormatXMLTemplate = 14 <span>XML Template .dotx<\/span><\/pre>\n<pre><span>  58:  <\/span><span>Const<\/span> wdFormatXMLTemplateMacroEnabled = 15 <span>XML Template Macros Enabled  .dotm<\/span><\/pre>\n<pre><span>  59:  <\/span>??<\/pre>\n<pre><span>  60:  <\/span><span>Const<\/span> TEXTMSG = 0<\/pre>\n<pre><span>  61:  <\/span><span>Const<\/span> HTMLMSG = 1<\/pre>\n<pre><span>  62:  <\/span>??<\/pre>\n<pre><span>  63:  <\/span><span> Global variables<\/span><\/pre>\n<pre><span>  64:  <\/span><span>Dim<\/span> arguments, bShowDebug, sOutFormat, iwdFormat, sOutExt, sFolder<\/pre>\n<pre><span>  65:  <\/span><span>Dim<\/span> owdo <span> As Word.Application<\/span><\/pre>\n<pre><span>  66:  <\/span><span>Dim<\/span> owdocs <span> As Word.Documents<\/span><\/pre>\n<pre><span>  67:  <\/span><span>Dim<\/span> ofso, bDateFilter, sDateFilterType, sDateFrom, sDateTo, iDays<\/pre>\n<pre><span>  68:  <\/span><span>Dim<\/span> bVerbose,output, sGoogleEmail<\/pre>\n<pre><span>  69:  <\/span><span>Dim<\/span> ol, ns<\/pre>\n<pre><span>  70:  <\/span>??<\/pre>\n<pre><span>  71:  <\/span><span>Set<\/span> arguments = WScript.Arguments<\/pre>\n<pre><span>  72:  <\/span>sOutFormat = <span>\"PDF\"<\/span><\/pre>\n<pre><span>  73:  <\/span>bDateFilter = <span>false<\/span><\/pre>\n<pre><span>  74:  <\/span>??<\/pre>\n<pre><span>  75:  <\/span>sDateFilterType = <span>\"\"<\/span><\/pre>\n<pre><span>  76:  <\/span>sDateFrom = <span>\"\"<\/span><\/pre>\n<pre><span>  77:  <\/span>sDateTo = <span>\"\"<\/span><\/pre>\n<pre><span>  78:  <\/span>sGoogleEmail = <span>\"\"<\/span><\/pre>\n<pre><span>  79:  <\/span>??<\/pre>\n<pre><span>  80:  <\/span>??<\/pre>\n<pre><span>  81:  <\/span><span>--------------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span>  82:  <\/span><span>Function<\/span> DetermineOutFormat(sOut)<\/pre>\n<pre><span>  83:  <\/span>   <span>Dim<\/span> iOut<\/pre>\n<pre><span>  84:  <\/span>   <span>Select<\/span> <span>Case<\/span> ucase(sOUt)<\/pre>\n<pre><span>  85:  <\/span>    <span>Case<\/span> <span>\"\"<\/span><\/pre>\n<pre><span>  86:  <\/span>        iOut = wdFormatPDF <\/pre>\n<pre><span>  87:  <\/span>        sOutExt = <span>\"pdf\"<\/span><\/pre>\n<pre><span>  88:  <\/span>  <span>Case<\/span> <span>\"PDF\"<\/span><\/pre>\n<pre><span>  89:  <\/span>        iOut = wdFormatPDF <\/pre>\n<pre><span>  90:  <\/span>  <span>Case<\/span> <span>\"XPS\"<\/span><\/pre>\n<pre><span>  91:  <\/span>        iOut = wdFormatXPS <\/pre>\n<pre><span>  92:  <\/span>  <span>Case<\/span> <span>\"DOC\"<\/span><\/pre>\n<pre><span>  93:  <\/span>        iOut = wdFormatDocument97<\/pre>\n<pre><span>  94:  <\/span>    <span>Case<\/span> <span>\"DOT\"<\/span><\/pre>\n<pre><span>  95:  <\/span>        iOUt = wdFormatTemplate <\/pre>\n<pre><span>  96:  <\/span>  <span>Case<\/span> <span>\"HTML\"<\/span><\/pre>\n<pre><span>  97:  <\/span>        iOut = wdFormatHTML <\/pre>\n<pre><span>  98:  <\/span>  <span>Case<\/span> <span>\"HTM\"<\/span><\/pre>\n<pre><span>  99:  <\/span>        iOut = wdFormatFilteredHTML <\/pre>\n<pre><span> 100:  <\/span>  <span>Case<\/span> <span>\"DOCX\"<\/span><\/pre>\n<pre><span> 101:  <\/span>        iOut = wdFormatXMLDocument <\/pre>\n<pre><span> 102:  <\/span>  <span>Case<\/span> <span>\"DOCM\"<\/span><\/pre>\n<pre><span> 103:  <\/span>        iOut = wdFormatXMLDocumentMacroEnabled <\/pre>\n<pre><span> 104:  <\/span>  <span>Case<\/span> <span>\"DOTX\"<\/span><\/pre>\n<pre><span> 105:  <\/span>        iOut = wdFormatXMLTemplate <\/pre>\n<pre><span> 106:  <\/span>  <span>Case<\/span> <span>\"DOTM\"<\/span><\/pre>\n<pre><span> 107:  <\/span>        iOUt = wdFormatXMLTemplateMacroEnabled <\/pre>\n<pre><span> 108:  <\/span>  <span>Case<\/span> <span>\"TXT\"<\/span><\/pre>\n<pre><span> 109:  <\/span>        iOut = wdFormatTextLineBreaks <\/pre>\n<pre><span> 110:  <\/span>  <span>Case<\/span> <span>\"XML\"<\/span><\/pre>\n<pre><span> 111:  <\/span>    iOUt = wdFormatXML <\/pre>\n<pre><span> 112:  <\/span>  <span>Case<\/span> <span>\"ASC\"<\/span><\/pre>\n<pre><span> 113:  <\/span>        iOUt = wdFormatDOSTextLineBreaks <\/pre>\n<pre><span> 114:  <\/span>  <span>Case<\/span> <span>\"DOS\"<\/span><\/pre>\n<pre><span> 115:  <\/span>        iOUt = wdFormatDOSText <\/pre>\n<pre><span> 116:  <\/span>        sOutExt = <span>\"txt\"<\/span><\/pre>\n<pre><span> 117:  <\/span>    <span>Case<\/span> <span>\"RTF\"<\/span><\/pre>\n<pre><span> 118:  <\/span>        iOut =     wdFormatRTF     <\/pre>\n<pre><span> 119:  <\/span>    <span>Case<\/span> <span>\"WEB\"<\/span><\/pre>\n<pre><span> 120:  <\/span>        iOUt = wdFormatWebArchive <\/pre>\n<pre><span> 121:  <\/span>    <span>Case<\/span> <span>else<\/span><\/pre>\n<pre><span> 122:  <\/span>       iOut = -1<\/pre>\n<pre><span> 123:  <\/span>  <span>End<\/span> <span>Select<\/span><\/pre>\n<pre><span> 124:  <\/span>  DetermineOutFormat = iOut<\/pre>\n<pre><span> 125:  <\/span>??<\/pre>\n<pre><span> 126:  <\/span><span>End<\/span> <span>Function<\/span><\/pre>\n<pre><span> 127:  <\/span>??<\/pre>\n<pre><span> 128:  <\/span>??<\/pre>\n<pre><span> 129:  <\/span><span>---------------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span> 130:  <\/span><span> ECHOUSAGE<\/span><\/pre>\n<pre><span> 131:  <\/span><span> Outputs the usage information.<\/span><\/pre>\n<pre><span> 132:  <\/span><span><\/span><\/pre>\n<pre><span> 133:  <\/span><span>Function<\/span> EchoUsage()<\/pre>\n<pre><span> 134:  <\/span>  <span>If<\/span> arguments.Count=0 <span>Or<\/span> arguments.Named.Exists(<span>\"help\"<\/span>) <span>Or<\/span> _<br>            arguments.Named.Exists(<span>\"h\"<\/span>) <span>or<\/span> iwdFormat=-1 <span>Then<\/span><\/pre>\n<pre><span> 135:  <\/span>   output.WriteLine <span>\"Save Word 2007 Compatible Document(s) in a different Format and more\"<\/span><\/pre>\n<pre><span> 136:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 137:  <\/span>   output.WriteLine <span>\"Usage: cscript \/nologo doc2pdf.vbs [<input-file>] [\/dir:<input-dir>] \" & _ <br>                           \"[\/date:created\/modified] [\/datefrom:mm-dd-yyyyy] \" & _<br>                           \"[\/dateto:mm-dd-yyyy] [\/days:nn] [\/f:<output-format>] \" & _<br>                           \"[\/o:<output-file>] [\/googledocs:<email>]\"<\/span><\/pre>\n<pre><span> 138:  <\/span>   output.WriteLine  <span>\"\"<\/span><\/pre>\n<pre><span> 139:  <\/span>   output.WriteLine  <span>\"Available Options:\"<\/span><\/pre>\n<pre><span> 140:  <\/span>   output.WriteLine  <span>\"==================\"<\/span><\/pre>\n<pre><span> 141:  <\/span>   output.WriteLine  <span>\"\/help - Specifies that this usage\/help information should be displayed.\"<\/span><\/pre>\n<pre><span> 142:  <\/span>   output.WriteLine  <span>\"\/verbose - Specifies that detailed information about the \" & _<br>                            \"processing should be displayed.\"<\/span><\/pre>\n<pre><span> 143:  <\/span>   output.WriteLine  <span>\"\"<\/span><\/pre>\n<pre><span> 144:  <\/span>   output.WriteLine  <span>\"Parameters (optional):\"<\/span><\/pre>\n<pre><span> 145:  <\/span>   output.WriteLine  <span>\"======================\"<\/span><\/pre>\n<pre><span> 146:  <\/span>   output.WriteLine  <span>\"\/dir:<input-dir>\"<\/span><\/pre>\n<pre><span> 147:  <\/span>   output.WriteLine  <span>\"    Directory Batch Processing. Use <input-file> argument as \" & _<br>                                \"filter option (e.g. *.DOCX or *.* for all)\"<\/span><\/pre>\n<pre><span> 148:  <\/span>   output.WriteLine  <span>\"\"<\/span><\/pre>\n<pre><span> 149:  <\/span>   output.WriteLine  <span>\"Date Filter Options\"<\/span><\/pre>\n<pre><span> 150:  <\/span>   output.WriteLine  <span>\"--------------------\"<\/span><\/pre>\n<pre><span> 151:  <\/span>   output.WriteLine <span>\"\/date:created\/modified - Date filter option\"<\/span><\/pre>\n<pre><span> 152:  <\/span>   output.WriteLine <span>\"\/datefrom:mm-dd-yyy - From Date for date-created or date-modfied filter\"<\/span><\/pre>\n<pre><span> 153:  <\/span>   output.WriteLine <span>\"\/datetto:mm-dd-yyy - To Date for date-created or date-modfied filter\"<\/span><\/pre>\n<pre><span> 154:  <\/span>   output.WriteLine <span>\" ...or ..\"<\/span><\/pre>\n<pre><span> 155:  <\/span>   output.WriteLine <span>\"\/days:nn - created\/changed within the last nn days. \"<\/span><\/pre>\n<pre><span> 156:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 157:  <\/span>   output.WriteLine <span>\"Output Options Parameters\"<\/span><\/pre>\n<pre><span> 158:  <\/span>   output.WriteLine <span>\"-------------------------\"<\/span><\/pre>\n<pre><span> 159:  <\/span>   output.WriteLine  <span>\" \/f:<format> Specifies the output format values:\"<\/span>     <\/pre>\n<pre><span> 160:  <\/span>   output.WriteLine  <span>\"    DOCX, DOCM, DOTX, DOTM, XML, PDF (default), XPS, TXT,\" & _<br>                            \" DOS, ASC, HTML, HTM, RTS, DOC, WEB\"<\/span> <\/pre>\n<pre><span> 161:  <\/span>   output.WriteLine  <span>\" \/o:<file> Optionally specification of output file.\"<\/span><\/pre>\n<pre><span> 162:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 163:  <\/span>   output.WriteLine <span>\"Send to Google Docs via Email Option\"<\/span><\/pre>\n<pre><span> 164:  <\/span>   output.WriteLine <span>\"------------------------------------\"<\/span><\/pre>\n<pre><span> 165:  <\/span>   output.WriteLine <span>\"Note: Google Docs only supports the import of documents in \" & _<br>                             \"DOC file format (Office 97).\"<\/span><\/pre>\n<pre><span> 166:  <\/span>   output.WriteLine <span>\"PDF files are not supported. The file size is also limited to \" & _<br>                             \"500KB per document.\"<\/span><\/pre>\n<pre><span> 167:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 168:  <\/span>   output.WriteLine <span>\"\/googledocs:<email> - your personal email to upload documents,\" & _<\/span><\/pre>\n<pre><span>                             \" which looks like: longstring@prod.writely.com \"<\/span><\/pre>\n<pre><span> 169:  <\/span>   output.WriteLine <span>\"\"<\/span>      <\/pre>\n<pre><span> 170:  <\/span>   output.WriteLine  <span>\"Examples:\"<\/span><\/pre>\n<pre><span> 171:  <\/span>   output.WriteLine  <span>\"=========\"<\/span><\/pre>\n<pre><span> 172:  <\/span>   output.WriteLine <span>\"1. Convert all Word 2007 documents (.docx) that were modified \" & _<br>                             \"on or since December 31, 2008 and are located in C:\\DOCS \" & _<br>                             \"to PDF and show detailed information about the processing.\"<\/span><\/pre>\n<pre><span> 173:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 174:  <\/span>   output.WriteLine <span>\"cscript \/nologo docx2pdf2.vbs *.docx \/f:PDF \/dir:C:\\DOCS \" & _<br>                           \"\/date:modified \/datefrom:12-31-2008 \/verbose\"<\/span><\/pre>\n<pre><span> 175:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 176:  <\/span>   output.WriteLine <span>\"2. Convert all Word 2007 documents (.docx) that where created \" & _<br>                           \"in the last 7 days and are located in C:\\MY DOCUMENTS to \" & _<br>                           \"Word 97 (.DOC) and send them to Google Docs. \"<\/span><\/pre>\n<pre><span> 177:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 178:  <\/span>   output.WriteLine <span>\"cscript \/nologo docx2pdf2.vbs *.docx \/f:DOC \/dir:\"<\/span><span>\"C:\\MY DOCUMENTS\"<\/span><span>\" \" & _<br>                           \"\/date:created \/days:7 \/googledocs:mysecretemail@prod.writely.com\"<\/span><\/pre>\n<pre><span> 179:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 180:  <\/span>   output.WriteLine <span>\"3. Convert a single Word 2007 Document C:\\DOCS\\mydocument.docx \" & _<br>                             \"to PDF and save it as C:\\MY DOCUMENTS\\mynewdocument.pdf\"<\/span><\/pre>\n<pre><span> 181:  <\/span>?? output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 182:  <\/span>   output.WriteLine <span>\"cscript \/nologo docx2pdf2.vbs \"<\/span><span>\"C:\\DOCS\\mydocument.docx\"<\/span><span>\" \" & _<br>                             \"\/o:\"<\/span><span>\"C:\\MY DOCUMENTS\\mynewdocument.pdf\"<\/span><span>\"\"<\/span><\/pre>\n<pre><span> 183:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 184:  <\/span>   output.WriteLine <span>\"4. Convert C:\\DOCS\\mydocument.docx to HTML and save it in \" & _<br>                             \"the same folder\"<\/span><\/pre>\n<pre><span> 185:  <\/span>   output.WriteLine <span>\"\"<\/span><\/pre>\n<pre><span> 186:  <\/span>   output.WriteLine <span>\"cscript \/nologo docx2pdf2.vbs \"<\/span><span>\"C:\\DOCS\\mydocument.docx\"<\/span><span>\" \/f:HTML\"<\/span><\/pre>\n<pre><span> 187:  <\/span>   output.WriteLine <span>\"\"<\/span>                         <\/pre>\n<pre><span> 188:  <\/span>  <span>End<\/span> <span>If<\/span> <\/pre>\n<pre><span> 189:  <\/span><span>End<\/span> <span>Function<\/span><\/pre>\n<pre><span> 190:  <\/span>??<\/pre>\n<pre><span> 191:  <\/span><span>-------------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span> 192:  <\/span><span> CHECKARGS<\/span><\/pre>\n<pre><span> 193:  <\/span><span> Makes some preliminary checks of the arguments.<\/span><\/pre>\n<pre><span> 194:  <\/span><span> Quits the application is any problem is found.<\/span><\/pre>\n<pre><span> 195:  <\/span><span><\/span><\/pre>\n<pre><span> 196:  <\/span><span>Function<\/span> CheckArgs()<\/pre>\n<pre><span> 197:  <\/span>  <span> Check that <doc-file> is specified<\/span><\/pre>\n<pre><span> 198:  <\/span>  <span>If<\/span> arguments.Unnamed.Count <> 1 <span>Then<\/span><\/pre>\n<pre><span> 199:  <\/span>    output.WriteLine <span>\"Error: Obligatory <doc-file> parameter missing!\"<\/span><\/pre>\n<pre><span> 200:  <\/span>    WScript.Quit 1<\/pre>\n<pre><span> 201:  <\/span>  <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 202:  <\/span>??<\/pre>\n<pre><span> 203:  <\/span><span>if<\/span> arguments.Named.Exists(<span>\"f\"<\/span>) <span>then<\/span><\/pre>\n<pre><span> 204:  <\/span>      sOutFormat = arguments.Named.Item(<span>\"f\"<\/span>)<\/pre>\n<pre><span> 205:  <\/span><span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 206:  <\/span>??<\/pre>\n<pre><span> 207:  <\/span><span>if<\/span> arguments.Named.Exists(<span>\"googledocs\"<\/span>) <span>then<\/span><\/pre>\n<pre><span> 208:  <\/span>  sGoogleEmail =  arguments.Named.Item(<span>\"googledocs\"<\/span>)<\/pre>\n<pre><span> 209:  <\/span><span>end<\/span> <span>if<\/span>    <\/pre>\n<pre><span> 210:  <\/span><span>if<\/span> sGoogleEmail <> <span>\"\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 211:  <\/span>   sOutFormat = <span>\"DOC\"<\/span><\/pre>\n<pre><span> 212:  <\/span><span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 213:  <\/span>??<\/pre>\n<pre><span> 214:  <\/span>sOutExt = sOutFormat<\/pre>\n<pre><span> 215:  <\/span>iwdFormat = DetermineOutFormat(sOutFormat)<\/pre>\n<pre><span> 216:  <\/span>??<\/pre>\n<pre><span> 217:  <\/span><span>if<\/span> arguments.Named.Exists(<span>\"date\"<\/span>) <span>then<\/span><\/pre>\n<pre><span> 218:  <\/span>??<\/pre>\n<pre><span> 219:  <\/span>    <span>if<\/span> arguments.Named.Exists(<span>\"days\"<\/span>) <span>then<\/span><\/pre>\n<pre><span> 220:  <\/span>       <span>if<\/span> isNumeric(arguments.Named.Item(<span>\"days\"<\/span>)) <span>then<\/span><\/pre>\n<pre><span> 221:  <\/span>          iDays = int(abs(arguments.Named.Item(<span>\"days\"<\/span>)))<\/pre>\n<pre><span> 222:  <\/span>          sDateFrom = formatdatetime(dateadd(<span>\"d\"<\/span>,iDays*-1,now),vbshortdate)<\/pre>\n<pre><span> 223:  <\/span>          sDateTo = formatdatetime(now,vbshortdate)<\/pre>\n<pre><span> 224:  <\/span>       <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 225:  <\/span>     <span>else<\/span><\/pre>\n<pre><span> 226:  <\/span>        <span>if<\/span> arguments.Named.Exists(<span>\"datefrom\"<\/span>) <span>then<\/span><\/pre>\n<pre><span> 227:  <\/span>          <span>if<\/span> isDate(arguments.Named.Item(<span>\"datefrom\"<\/span>)) <span>then<\/span><\/pre>\n<pre><span> 228:  <\/span>            sDateFrom = formatdatetime(arguments.Named.Item(<span>\"datefrom\"<\/span>),vbshortdate)<\/pre>\n<pre><span> 229:  <\/span>          <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 230:  <\/span>        <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 231:  <\/span>         <span>if<\/span> arguments.Named.Exists(<span>\"dateto\"<\/span>) <span>then<\/span><\/pre>\n<pre><span> 232:  <\/span>           <span>if<\/span> isDate(arguments.Named.Item(<span>\"dateto\"<\/span>)) <span>then<\/span><\/pre>\n<pre><span> 233:  <\/span>              sDateTo = formatdatetime(arguments.Named.Item(<span>\"dateto\"<\/span>),vbshortdate)<\/pre>\n<pre><span> 234:  <\/span>           <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 235:  <\/span>         <span>else<\/span><\/pre>\n<pre><span> 236:  <\/span>             sDateTo = formatdatetime(now,vbshortdate)<\/pre>\n<pre><span> 237:  <\/span>         <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 238:  <\/span>         <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 239:  <\/span>         <\/pre>\n<pre><span> 240:  <\/span>     <span>if<\/span> arguments.Named.Item(<span>\"date\"<\/span>) = <span>\"created\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 241:  <\/span>        sDateFilterType = <span>\"c\"<\/span><\/pre>\n<pre><span> 242:  <\/span>     <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 243:  <\/span>     <span>if<\/span> arguments.Named.Item(<span>\"date\"<\/span>) = <span>\"modified\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 244:  <\/span>        sDateFilterType = <span>\"m\"<\/span><\/pre>\n<pre><span> 245:  <\/span>     <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 246:  <\/span>    <\/pre>\n<pre><span> 247:  <\/span>     <span>if<\/span> sDateFilterType <> <span>\"\"<\/span> <span>and<\/span> sDateFrom <> <span>\"\"<\/span> <span>and<\/span> sDateTo <> <span>\"\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 248:  <\/span>        bDateFilter = <span>true<\/span><\/pre>\n<pre><span> 249:  <\/span>                <span>if<\/span> bVerbose = <span>true<\/span> <span>then<\/span><\/pre>\n<pre><span> 250:  <\/span>                   output.WriteLine <span>\"Date Filter on! From Date: \"<\/span> & sDateFrom & _<br><span>\", To Date: \"<\/span> & sDateTo & <span>\", Filter: \"<\/span> & sDateFilterType<\/pre>\n<pre><span> 251:  <\/span>                <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 252:  <\/span>     <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 253:  <\/span>??<\/pre>\n<pre><span> 254:  <\/span><span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 255:  <\/span>??<\/pre>\n<pre><span> 256:  <\/span>??<\/pre>\n<pre><span> 257:  <\/span>??<\/pre>\n<pre><span> 258:  <\/span>??<\/pre>\n<pre><span> 259:  <\/span><span>End<\/span> <span>Function<\/span><\/pre>\n<pre><span> 260:  <\/span>??<\/pre>\n<pre><span> 261:  <\/span><span>------------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span> 262:  <\/span><span> DOC2PDF<\/span><\/pre>\n<pre><span> 263:  <\/span><span> Converts a Word document to PDF using Word 2007.<\/span><\/pre>\n<pre><span> 264:  <\/span><span> Input:<\/span><\/pre>\n<pre><span> 265:  <\/span><span> sDocFile - Full path to Word document.<\/span><\/pre>\n<pre><span> 266:  <\/span><span> sPDFFile - Optional full path to output file.<\/span><\/pre>\n<pre><span> 267:  <\/span><span><\/span><\/pre>\n<pre><span> 268:  <\/span><span> If not specified the output PDF file<\/span><\/pre>\n<pre><span> 269:  <\/span><span> will be the same as the sDocFile except<\/span><\/pre>\n<pre><span> 270:  <\/span><span> file extension will be .pdf.<\/span><\/pre>\n<pre><span> 271:  <\/span><span><\/span><\/pre>\n<pre><span> 272:  <\/span><span>Function<\/span> DOC2PDF( sDocFile, sPDFFile )<\/pre>\n<pre><span> 273:  <\/span>??<\/pre>\n<pre><span> 274:  <\/span>??<\/pre>\n<pre><span> 275:  <\/span>  <span>Dim<\/span> owdoc <span> As Word.Document<\/span><\/pre>\n<pre><span> 276:  <\/span>  <span>Dim<\/span> sPrevPrinter <span> As String<\/span><\/pre>\n<pre><span> 277:  <\/span>??<\/pre>\n<pre><span> 278:  <\/span>??<\/pre>\n<pre><span> 279:  <\/span>  <span>if<\/span> sFolder = <span>\"\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 280:  <\/span>      sDocFile = ofso.GetAbsolutePathName(sDocFile)<\/pre>\n<pre><span> 281:  <\/span>        sTmpFolder = ofso.GetParentFolderName(sDocFile)<\/pre>\n<pre><span> 282:  <\/span>  <span>else<\/span><\/pre>\n<pre><span> 283:  <\/span>    sDocFile = sDocFile<\/pre>\n<pre><span> 284:  <\/span>    sTmpFolder = sFolder<\/pre>\n<pre><span> 285:  <\/span>  <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 286:  <\/span>??<\/pre>\n<pre><span> 287:  <\/span>  <span>If<\/span> Len(sPDFFile)=0 <span>Then<\/span><\/pre>\n<pre><span> 288:  <\/span>    sPDFFile = ofso.GetBaseName(sDocFile) + <span>\".\"<\/span> + lcase(sOutExt)<\/pre>\n<pre><span> 289:  <\/span>  <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 290:  <\/span>??<\/pre>\n<pre><span> 291:  <\/span>  <span>If<\/span> Len(ofso.GetParentFolderName(sPDFFile))=0 <span>Then<\/span><\/pre>\n<pre><span> 292:  <\/span>    sPDFFile = sTmpFolder + <span>\"\\\"<\/span> + sPDFFile<\/pre>\n<pre><span> 293:  <\/span>  <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 294:  <\/span>??<\/pre>\n<pre><span> 295:  <\/span>??<\/pre>\n<pre><span> 296:  <\/span>  <span> Enable this line if you want to disable autoexecute macros<\/span><\/pre>\n<pre><span> 297:  <\/span>  <span> owdo.WordBasic.DisableAutoMacros<\/span><\/pre>\n<pre><span> 298:  <\/span>     <span>if<\/span> bVerbose = <span>true<\/span> <span>then<\/span><\/pre>\n<pre><span> 299:  <\/span>         output.WriteLine <span>\"Converting: \"<\/span> & sDocFile <\/pre>\n<pre><span> 300:  <\/span>     <span>end<\/span> <span>if<\/span>                <\/pre>\n<pre><span> 301:  <\/span>  <span> Open the Word document<\/span><\/pre>\n<pre><span> 302:  <\/span>  <span>Set<\/span> owdoc = owdocs.Open(sDocFile)<\/pre>\n<pre><span> 303:  <\/span>??<\/pre>\n<pre><span> 304:  <\/span>  <span> Let Word document save as PDF<\/span><\/pre>\n<pre><span> 305:  <\/span>  <span> - for documentation of SaveAs() method,<\/span><\/pre>\n<pre><span> 306:  <\/span>  <span>   see http:\/\/msdn2.microsoft.com\/en-us\/library\/bb221597.aspx <\/span><\/pre>\n<pre><span> 307:  <\/span>  owdoc.SaveAs sPDFFile, iwdFormat <\/pre>\n<pre><span> 308:  <\/span>??<\/pre>\n<pre><span> 309:  <\/span>  owdoc.Close WdDoNotSaveChanges<\/pre>\n<pre><span> 310:  <\/span>??<\/pre>\n<pre><span> 311:  <\/span>     <span>if<\/span> bVerbose = <span>true<\/span> <span>then<\/span><\/pre>\n<pre><span> 312:  <\/span>         output.WriteLine <span>\"Saved As: \"<\/span> & sPDFFile & <span>\"(Format: \"<\/span> & iwdFormat & <span>\")\"<\/span><\/pre>\n<pre><span> 313:  <\/span>     <span>end<\/span> <span>if<\/span>                <\/pre>\n<pre><span> 314:  <\/span>??<\/pre>\n<pre><span> 315:  <\/span>     <span>if<\/span> sGoogleEmail <> <span>\"\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 316:  <\/span>        SendEmailToGoogleDocs sGoogleEmail, sPDFFile<\/pre>\n<pre><span> 317:  <\/span>     <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 318:  <\/span><span>End<\/span> <span>Function<\/span><\/pre>\n<pre><span> 319:  <\/span>??<\/pre>\n<pre><span> 320:  <\/span><span>------------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span> 321:  <\/span><span> Returns an array with the file names that match Path.<\/span><\/pre>\n<pre><span> 322:  <\/span><span> The Path string may contain the wildcard characters \"*\"<\/span><\/pre>\n<pre><span> 323:  <\/span><span> and \"?\" in the file name component. The same rules apply<\/span><\/pre>\n<pre><span> 324:  <\/span><span> as with the MSDOS DIR command.<\/span><\/pre>\n<pre><span> 325:  <\/span><span> If Path is a directory, the contents of this directory is listed.<\/span><\/pre>\n<pre><span> 326:  <\/span><span> If Path is empty, the current directory is listed.<\/span><\/pre>\n<pre><span> 327:  <\/span><span> Author: Christian dHeureuse (www.source-code.biz)<\/span><\/pre>\n<pre><span> 328:  <\/span>??<\/pre>\n<pre><span> 329:  <\/span><span>Public<\/span>  <span>Function<\/span> ListDir (<span>ByVal<\/span> Path)<\/pre>\n<pre><span> 330:  <\/span>   <span>Dim<\/span> fso: <span>Set<\/span> fso = CreateObject(<span>\"Scripting.FileSystemObject\"<\/span>)<\/pre>\n<pre><span> 331:  <\/span>   <span>If<\/span> Path = <span>\"\"<\/span> <span>then<\/span> Path = <span>\"*.*\"<\/span><\/pre>\n<pre><span> 332:  <\/span>   <span>Dim<\/span> Parent, Filter<\/pre>\n<pre><span> 333:  <\/span>   <span>if<\/span> fso.FolderExists(Path) <span>then<\/span>      <span> Path is a directory<\/span><\/pre>\n<pre><span> 334:  <\/span>      Parent = Path<\/pre>\n<pre><span> 335:  <\/span>      Filter = <span>\"*\"<\/span><\/pre>\n<pre><span> 336:  <\/span>     <span>Else<\/span><\/pre>\n<pre><span> 337:  <\/span>      Parent = fso.GetParentFolderName(Path)<\/pre>\n<pre><span> 338:  <\/span>      <span>If<\/span> Parent = <span>\"\"<\/span> <span>Then<\/span> <span>If<\/span> Right(Path,1) = <span>\":\"<\/span> <span>Then<\/span> Parent = Path: <span>Else<\/span> Parent = <span>\".\"<\/span><\/pre>\n<pre><span> 339:  <\/span>      Filter = fso.GetFileName(Path)<\/pre>\n<pre><span> 340:  <\/span>      <span>If<\/span> Filter = <span>\"\"<\/span> <span>Then<\/span> Filter = <span>\"*\"<\/span><\/pre>\n<pre><span> 341:  <\/span>      <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 342:  <\/span>   <span>ReDim<\/span> a(10)<\/pre>\n<pre><span> 343:  <\/span>   <span>Dim<\/span> n: n = 0<\/pre>\n<pre><span> 344:  <\/span>   <span>Dim<\/span> Folder: <span>Set<\/span> Folder = fso.GetFolder(Parent)<\/pre>\n<pre><span> 345:  <\/span>   <span>Dim<\/span> Files: <span>Set<\/span> Files = Folder.Files<\/pre>\n<pre><span> 346:  <\/span>   <span>Dim<\/span> File<\/pre>\n<pre><span> 347:  <\/span>   <span>For<\/span> <span>Each<\/span> File <span>In<\/span> Files<\/pre>\n<pre><span> 348:  <\/span>??<\/pre>\n<pre><span> 349:  <\/span>        bDateFiltered = <span>false<\/span><\/pre>\n<pre><span> 350:  <\/span>      <span>if<\/span> bDateFilter = <span>true<\/span> <span>then<\/span><\/pre>\n<pre><span> 351:  <\/span>           <span>if<\/span> sDateFilterType = <span>\"c\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 352:  <\/span>             dDate = File.DateCreated <\/pre>\n<pre><span> 353:  <\/span>           <span>end<\/span> <span>if<\/span>            <\/pre>\n<pre><span> 354:  <\/span>           <span>if<\/span> sDateFilterType = <span>\"m\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 355:  <\/span>             dDate = File.DateLastModified<\/pre>\n<pre><span> 356:  <\/span>           <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 357:  <\/span>                     <span>if<\/span> datediff(<span>\"d\"<\/span>,dDate,sDateFrom) >= 0  <span>or<\/span> _<br>???????????????????????????????????????????????????????????? datediff(<span>\"d\"<\/span>,dDate,sDateTo) < 0 <span>then<\/span><\/pre>\n<pre><span> 358:  <\/span>                       bDateFiltered = <span>true<\/span><\/pre>\n<pre><span> 359:  <\/span>                         <span>if<\/span> bVerbose = <span>true<\/span> <span>then<\/span><\/pre>\n<pre><span> 360:  <\/span>                             output.WriteLine File.Name & <span>\" skipped (Date Filter), (dc: \"<\/span> & _<br>                                    File.DateCreated & <span>\", dm: \"<\/span> & File.DateLastModified & <span>\")\"<\/span> <\/pre>\n<pre><span> 361:  <\/span>                         <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 362:  <\/span>                     <span>end<\/span> <span>if<\/span>      <\/pre>\n<pre><span> 363:  <\/span>            <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 364:  <\/span>      <span>if<\/span>  bDateFiltered = <span>false<\/span> <span>then<\/span><\/pre>\n<pre><span> 365:  <\/span>          <span>If<\/span> CompareFileName(File.Name,Filter) <span>Then<\/span><\/pre>\n<pre><span> 366:  <\/span>              <span>If<\/span> n > UBound(a) <span>Then<\/span> <span>ReDim<\/span> <span>Preserve<\/span> a(n*2)<\/pre>\n<pre><span> 367:  <\/span>              a(n) = File.Path<\/pre>\n<pre><span> 368:  <\/span>              n = n + 1<\/pre>\n<pre><span> 369:  <\/span>                  <span>else<\/span><\/pre>\n<pre><span> 370:  <\/span>                         <span>if<\/span> bVerbose = <span>true<\/span> <span>then<\/span><\/pre>\n<pre><span> 371:  <\/span>                             output.WriteLine File.Name & _<br>?????????????????????????????????????????????????????????????????????? <span>\" skipped (File Path Filter Argument)\"<\/span> <\/pre>\n<pre><span> 372:  <\/span>                         <span>end<\/span> <span>if<\/span>                    <\/pre>\n<pre><span> 373:  <\/span>          <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 374:  <\/span>            <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 375:  <\/span>      <span>Next<\/span><\/pre>\n<pre><span> 376:  <\/span>   <span>ReDim<\/span> <span>Preserve<\/span> a(n-1)<\/pre>\n<pre><span> 377:  <\/span>   ListDir = a<\/pre>\n<pre><span> 378:  <\/span>   <span>End<\/span> <span>Function<\/span><\/pre>\n<pre><span> 379:  <\/span><span>-----------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span> 380:  <\/span><span>Private<\/span> <span>Function<\/span> CompareFileName (<span>ByVal<\/span> Name, <span>ByVal<\/span> Filter) <span> (recursive)<\/span><\/pre>\n<pre><span> 381:  <\/span>   CompareFileName = <span>False<\/span><\/pre>\n<pre><span> 382:  <\/span>   <span>Dim<\/span> np, fp: np = 1: fp = 1<\/pre>\n<pre><span> 383:  <\/span>   <span>Do<\/span><\/pre>\n<pre><span> 384:  <\/span>      <span>If<\/span> fp > Len(Filter) <span>Then<\/span> CompareFileName = np > len(name): <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 385:  <\/span>      <span>If<\/span> Mid(Filter,fp) = <span>\".*\"<\/span> <span>Then<\/span>    <span> special case: \".*\" at end of filter<\/span><\/pre>\n<pre><span> 386:  <\/span>         <span>If<\/span> np > Len(Name) <span>Then<\/span> CompareFileName = <span>True<\/span>: <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 387:  <\/span>         <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 388:  <\/span>      <span>If<\/span> Mid(Filter,fp) = <span>\".\"<\/span> <span>Then<\/span>     <span> special case: \".\" at end of filter<\/span><\/pre>\n<pre><span> 389:  <\/span>         CompareFileName = np > Len(Name): <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 390:  <\/span>         <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 391:  <\/span>      <span>Dim<\/span> fc: fc = Mid(Filter,fp,1): fp = fp + 1<\/pre>\n<pre><span> 392:  <\/span>      <span>Select<\/span> <span>Case<\/span> fc<\/pre>\n<pre><span> 393:  <\/span>         <span>Case<\/span> <span>\"*\"<\/span><\/pre>\n<pre><span> 394:  <\/span>            CompareFileName = CompareFileName2(name,np,filter,fp)<\/pre>\n<pre><span> 395:  <\/span>            <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 396:  <\/span>         <span>Case<\/span> <span>\"?\"<\/span><\/pre>\n<pre><span> 397:  <\/span>            <span>If<\/span> np <= Len(Name) <span>And<\/span> Mid(Name,np,1) <> <span>\".\"<\/span> <span>Then<\/span> np = np + 1<\/pre>\n<pre><span> 398:  <\/span>         <span>Case<\/span> <span>Else<\/span><\/pre>\n<pre><span> 399:  <\/span>            <span>If<\/span> np > Len(Name) <span>Then<\/span> <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 400:  <\/span>            <span>Dim<\/span> nc: nc = Mid(Name,np,1): np = np + 1<\/pre>\n<pre><span> 401:  <\/span>            <span>If<\/span> Strcomp(fc,nc,vbTextCompare)<>0 <span>Then<\/span> <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 402:  <\/span>         <span>End<\/span> <span>Select<\/span><\/pre>\n<pre><span> 403:  <\/span>      <span>Loop<\/span><\/pre>\n<pre><span> 404:  <\/span>   <span>End<\/span> <span>Function<\/span><\/pre>\n<pre><span> 405:  <\/span><span>-------------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span> 406:  <\/span><span>Private<\/span> <span>Function<\/span> CompareFileName2 (<span>ByVal<\/span> Name, <span>ByVal<\/span> np0, <span>ByVal<\/span> Filter, <span>ByVal<\/span> fp0)<\/pre>\n<pre><span> 407:  <\/span>   <span>Dim<\/span> fp: fp = fp0<\/pre>\n<pre><span> 408:  <\/span>   <span>Dim<\/span> fc2<\/pre>\n<pre><span> 409:  <\/span>   <span>Do<\/span>                                  <span> skip over \"*\" and \"?\" characters in filter<\/span><\/pre>\n<pre><span> 410:  <\/span>      <span>If<\/span> fp > Len(Filter) <span>Then<\/span> CompareFileName2 = <span>True<\/span>: <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 411:  <\/span>      fc2 = Mid(Filter,fp,1): fp = fp + 1<\/pre>\n<pre><span> 412:  <\/span>      <span>If<\/span> fc2 <> <span>\"*\"<\/span> <span>And<\/span> fc2 <> <span>\"?\"<\/span> <span>Then<\/span> <span>Exit<\/span> <span>Do<\/span><\/pre>\n<pre><span> 413:  <\/span>      <span>Loop<\/span><\/pre>\n<pre><span> 414:  <\/span>   <span>If<\/span> fc2 = <span>\".\"<\/span> <span>Then<\/span><\/pre>\n<pre><span> 415:  <\/span>      <span>If<\/span> Mid(Filter,fp) = <span>\"*\"<\/span> <span>Then<\/span>     <span> special case: \".*\" at end of filter<\/span><\/pre>\n<pre><span> 416:  <\/span>         CompareFileName2 = <span>True<\/span>: <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 417:  <\/span>         <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 418:  <\/span>      <span>If<\/span> fp > Len(Filter) <span>Then<\/span>         <span> special case: \".\" at end of filter<\/span><\/pre>\n<pre><span> 419:  <\/span>         CompareFileName2 = InStr(np0,Name,<span>\".\"<\/span>) = 0: <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 420:  <\/span>         <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 421:  <\/span>      <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 422:  <\/span>   <span>Dim<\/span> np<\/pre>\n<pre><span> 423:  <\/span>   <span>For<\/span> np = np0 <span>To<\/span> Len(Name)<\/pre>\n<pre><span> 424:  <\/span>      <span>Dim<\/span> nc: nc = Mid(Name,np,1)<\/pre>\n<pre><span> 425:  <\/span>      <span>If<\/span> StrComp(fc2,nc,vbTextCompare)=0 <span>Then<\/span><\/pre>\n<pre><span> 426:  <\/span>         <span>If<\/span> CompareFileName(Mid(Name,np+1),Mid(Filter,fp)) <span>Then<\/span><\/pre>\n<pre><span> 427:  <\/span>            CompareFileName2 = <span>True<\/span>: <span>Exit<\/span> <span>Function<\/span><\/pre>\n<pre><span> 428:  <\/span>            <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 429:  <\/span>         <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 430:  <\/span>      <span>Next<\/span><\/pre>\n<pre><span> 431:  <\/span>   CompareFileName2 = <span>False<\/span><\/pre>\n<pre><span> 432:  <\/span>   <span>End<\/span> <span>Function<\/span><\/pre>\n<pre><span> 433:  <\/span><span>-------------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span> 434:  <\/span>     <\/pre>\n<pre><span> 435:  <\/span><span>Sub<\/span> SendEmailToGoogleDocs(sToEmail, sFileAttachment)<\/pre>\n<pre><span> 436:  <\/span>??<\/pre>\n<pre><span> 437:  <\/span><span>Dim<\/span> ToAddress<\/pre>\n<pre><span> 438:  <\/span><span>Dim<\/span> MessageSubject<\/pre>\n<pre><span> 439:  <\/span><span>Dim<\/span> MessageBody<\/pre>\n<pre><span> 440:  <\/span><span>Dim<\/span> MessageAttachment<\/pre>\n<pre><span> 441:  <\/span><span>Dim<\/span> newMail<\/pre>\n<pre><span> 442:  <\/span> <\/pre>\n<pre><span> 443:  <\/span>??<\/pre>\n<pre><span> 444:  <\/span>??<\/pre>\n<pre><span> 445:  <\/span><span>Set<\/span> oCheckFile = oFso.GetFile(sFileAttachment)<\/pre>\n<pre><span> 446:  <\/span><span>if<\/span> oCheckFile.Size > iGoogleDocsSizeLimit <span>then<\/span><\/pre>\n<pre><span> 447:  <\/span><span>File is too large<\/span><\/pre>\n<pre><span> 448:  <\/span>  output.WriteLine sFileAttachment & <span>\" could not be sent to Google Docs. \" & _<br>              \"It is too large (limit 500KB). File Size: \"<\/span> & oCheckFile.Size\/1024 & <span>\"KB\"<\/span> <\/pre>\n<pre><span> 449:  <\/span><span>else<\/span><\/pre>\n<pre><span> 450:  <\/span>??<\/pre>\n<pre><span> 451:  <\/span>    ToAddress = sToEmail<\/pre>\n<pre><span> 452:  <\/span>    MessageSubject = oFso.GetFileName(sFileAttachment)<\/pre>\n<pre><span> 453:  <\/span>    MessageBody = <span>\"\"<\/span><\/pre>\n<pre><span> 454:  <\/span>??<\/pre>\n<pre><span> 455:  <\/span>        <\/pre>\n<pre><span> 456:  <\/span>        <\/pre>\n<pre><span> 457:  <\/span>        <span>Select<\/span> <span>Case<\/span> EmailSendMethod <\/pre>\n<pre><span> 458:  <\/span>        <\/pre>\n<pre><span> 459:  <\/span>        <span>Case<\/span> 1<\/pre>\n<pre><span> 460:  <\/span>              <span>Send EMail using MAPI<\/span><\/pre>\n<pre><span> 461:  <\/span>              <\/pre>\n<pre><span> 462:  <\/span>          <span>Set<\/span> ol = WScript.CreateObject(<span>\"Outlook.Application\"<\/span>)<\/pre>\n<pre><span> 463:  <\/span>          <span>Set<\/span> ns = ol.getNamespace(<span>\"MAPI\"<\/span>)<\/pre>\n<pre><span> 464:  <\/span>          ns.logon <span>\"\"<\/span>,<span>\"\"<\/span>,<span>true<\/span>,<span>false<\/span><\/pre>\n<pre><span> 465:  <\/span>           <\/pre>\n<pre><span> 466:  <\/span>          <span>Set<\/span> newMail = ol.CreateItem(olMailItem)<\/pre>\n<pre><span> 467:  <\/span>          newMail.Subject = MessageSubject<\/pre>\n<pre><span> 468:  <\/span>          newMail.Body = MessageBody &vbCrLf<\/pre>\n<pre><span> 469:  <\/span>          <\/pre>\n<pre><span> 470:  <\/span>          MessageAttachment = sFileAttachment<\/pre>\n<pre><span> 471:  <\/span>          newMail.Attachments.Add(MessageAttachment).Displayname = _<br>???????????????????????????????????????????????????????????????????????????????????????? oFso.GetFileName(sFileAttachment)<\/pre>\n<pre><span> 472:  <\/span>          <\/pre>\n<pre><span> 473:  <\/span>          <span> validate the recipient, just in case???<\/span><\/pre>\n<pre><span> 474:  <\/span>          <span>Set<\/span> myRecipient = ns.CreateRecipient(ToAddress)<\/pre>\n<pre><span> 475:  <\/span>          myRecipient.Resolve<\/pre>\n<pre><span> 476:  <\/span>          <\/pre>\n<pre><span> 477:  <\/span>          <span>If<\/span> <span>Not<\/span> myRecipient.Resolved <span>Then<\/span><\/pre>\n<pre><span> 478:  <\/span>              output.WriteLine  sToEmail & _<br><span>\" is an Unknown recipient, cannot send email with \"<\/span> & sFileAttachment<\/pre>\n<pre><span> 479:  <\/span>          <span>Else<\/span><\/pre>\n<pre><span> 480:  <\/span>             newMail.Recipients.Add(myRecipient)<\/pre>\n<pre><span> 481:  <\/span>             newMail.Send<\/pre>\n<pre><span> 482:  <\/span>                   <span>if<\/span> bVerbose = <span>true<\/span> <span>then<\/span><\/pre>\n<pre><span> 483:  <\/span>                          output.WriteLine <span>\"Email for Google Docs for \"<\/span> & _<br>???????????????????????????????????????????????????????????????? sFileAttachment & <span>\" was created in our Outlook Outbox folder.\"<\/span> <\/pre>\n<pre><span> 484:  <\/span>                 <span>end<\/span> <span>if<\/span>                     <\/pre>\n<pre><span> 485:  <\/span>          <span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 486:  <\/span>      <\/pre>\n<pre><span> 487:  <\/span>          <span>Set<\/span> ol = <span>Nothing<\/span><\/pre>\n<pre><span> 488:  <\/span>        <span>Case<\/span> 2<\/pre>\n<pre><span> 489:  <\/span>        <span>Send EMail Using CDO<\/span><\/pre>\n<pre><span> 490:  <\/span>          msgType  = 0 <\/pre>\n<pre><span> 491:  <\/span>        <\/pre>\n<pre><span> 492:  <\/span>            <span>Set<\/span> newMail = Wscript.CreateObject(<span>\"CDO.Message\"<\/span>)<\/pre>\n<pre><span> 493:  <\/span>?????? newMail.<span>To<\/span> = sToEmail<\/pre>\n<pre><span> 494:  <\/span>            newMail.From = sToEmail<\/pre>\n<pre><span> 495:  <\/span>            newMail.Subject = MessageSubject<\/pre>\n<pre><span> 496:  <\/span>            <span>if<\/span> msgType = TEXTMSG <span>then<\/span><\/pre>\n<pre><span> 497:  <\/span>?????????????????? newMail.TextBody = MessageBody &vbCrLf<\/pre>\n<pre><span> 498:  <\/span>            <span>else<\/span><\/pre>\n<pre><span> 499:  <\/span>???????????????????? newMail.HTMLBody = MessageBody &vbCrLf<\/pre>\n<pre><span> 500:  <\/span>            <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 501:  <\/span>            newMail.AddAttachment  sFileAttachment<\/pre>\n<pre><span> 502:  <\/span>           <span>if<\/span> bVerbose = <span>true<\/span> <span>then<\/span><\/pre>\n<pre><span> 503:  <\/span>              output.WriteLine <span>\"Email for Google Docs for \"<\/span> & sFileAttachment & _<br>???????????????????????????????????????? <span>\" was sent via CDO\"<\/span> <\/pre>\n<pre><span> 504:  <\/span>           <span>end<\/span> <span>if<\/span>                     <\/pre>\n<pre><span> 505:  <\/span>            <\/pre>\n<pre><span> 506:  <\/span>           <\/pre>\n<pre><span> 507:  <\/span><span>      newMail.Configuration.Fields.Item _<\/span><\/pre>\n<pre><span> 508:  <\/span><span>            (\"http:\/\/schemas.microsoft.com\/cdo\/configuration\/sendusing\") = 2<\/span><\/pre>\n<pre><span> 509:  <\/span><span>      newMail.Configuration.Fields.Item _<\/span><\/pre>\n<pre><span> 510:  <\/span><span>            (\"http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserver\") =<\/span><\/pre>\n<pre><span> 511:  <\/span><span>      newMail.Configuration.Fields.Item _<\/span><\/pre>\n<pre><span> 512:  <\/span><span>            (\"http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserverport\") = 25<\/span><\/pre>\n<pre><span> 513:  <\/span><span>      newMail.Configuration.Fields.Update<\/span><\/pre>\n<pre><span> 514:  <\/span>        <\/pre>\n<pre><span> 515:  <\/span>??<\/pre>\n<pre><span> 516:  <\/span>        newMail.Send<\/pre>\n<pre><span> 517:  <\/span>??<\/pre>\n<pre><span> 518:  <\/span>        <span>set<\/span> newMail = <span>Nothing<\/span><\/pre>\n<pre><span> 519:  <\/span>??<\/pre>\n<pre><span> 520:  <\/span>    <span>End<\/span> <span>Select<\/span><\/pre>\n<pre><span> 521:  <\/span>        <\/pre>\n<pre><span> 522:  <\/span><span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 523:  <\/span>??<\/pre>\n<pre><span> 524:  <\/span><span>End<\/span> <span>Sub<\/span>     <\/pre>\n<pre><span> 525:  <\/span>??<\/pre>\n<pre><span> 526:  <\/span><span>------------------------------------------------------------------------------------------<\/span><\/pre>\n<pre><span> 527:  <\/span><span>Sub<\/span> ForceCscript(bForceRelance) <\/pre>\n<pre><span> 528:  <\/span><span>Force to reload the program in non interactive mode <\/span><\/pre>\n<pre><span> 529: <\/span><span>If<\/span> (right(Ucase(WScript.FullName),11)=<span>\"WSCRIPT.EXE\"<\/span>) <span>and<\/span> bForceRelance <span>Then<\/span> <\/pre>\n<pre><span> 530:  <\/span> <span>Dim<\/span> WshShell,args,objArgs,argname, I , sFullCall<\/pre>\n<pre><span> 531:  <\/span> <span>Set<\/span> WshShell = CreateObject(<span>\"WScript.Shell\"<\/span>) <\/pre>\n<pre><span> 532:  <\/span> args=<span>\"\"<\/span> <\/pre>\n<pre><span> 533:   <\/span><span>If<\/span> Wscript.Arguments.Count > 0 <span>Then<\/span> <\/pre>\n<pre><span> 534:  <\/span>  <span>Set<\/span> objArgs = Wscript.arguments.Unnamed <\/pre>\n<pre><span> 535:  <\/span>  <span>For<\/span> I = 0 <span>to<\/span> objArgs.Count - 1<\/pre>\n<pre><span> 536:  <\/span>     <span>if<\/span> instr(objArgs(I),<span>\" \"<\/span>) > 0 <span>then<\/span><\/pre>\n<pre><span> 537:  <\/span>       args = args & <span>\" \"<\/span><span>\"\"<\/span> & objArgs(I) & <span>\"\"<\/span><span>\"\"<\/span><\/pre>\n<pre><span> 538:  <\/span>     <span>else<\/span> <\/pre>\n<pre><span> 539:  <\/span>      args = args & <span>\" \"<\/span> & objArgs(I)<\/pre>\n<pre><span> 540:  <\/span>     <span>end<\/span> <span>if<\/span>         <\/pre>\n<pre><span> 541:  <\/span>  <span>Next<\/span> <\/pre>\n<pre><span> 542:  <\/span>  <span>For<\/span> <span>each<\/span> argname <span>in<\/span> Wscript.arguments.Named <\/pre>\n<pre><span> 543:  <\/span>     <span>if<\/span> instr(Wscript.arguments.Named.Item(argname),<span>\" \"<\/span>) > 0 <span>then<\/span><\/pre>\n<pre><span> 544:  <\/span>        args = args & <span>\" \/\"<\/span> & argname & <span>\":\"<\/span><span>\"\"<\/span> & Wscript.arguments.Named.Item(argname) & <span>\"\"<\/span><span>\"\"<\/span><\/pre>\n<pre><span> 545:  <\/span>     <span>else<\/span><\/pre>\n<pre><span> 546:  <\/span>        <span>if<\/span> Wscript.arguments.Named.Item(argname) = <span>\"\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 547:  <\/span>                args = args & <span>\" \/\"<\/span> & argname <\/pre>\n<pre><span> 548:  <\/span>         <span>else<\/span><\/pre>\n<pre><span> 549:  <\/span>              args = args & <span>\" \/\"<\/span> & argname & <span>\":\"<\/span> & Wscript.arguments.Named.Item(argname)<\/pre>\n<pre><span> 550:  <\/span>         <span>end<\/span> <span>if<\/span>        <\/pre>\n<pre><span> 551:  <\/span>     <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 552:  <\/span>  <span>Next<\/span><\/pre>\n<pre><span> 553:   <\/span><span>End<\/span> <span>If<\/span><\/pre>\n<pre><span> 554:  <\/span> sFullCall =  WshShell.ExpandEnvironmentStrings(<span>\"%COMSPEC%\"<\/span>) & <span>\" \/C cscript.exe \"<\/span><span>\"\"<\/span> & _<br>                     Wscript.ScriptFullName & <span>\"\"<\/span><span>\"\"<\/span> & args<\/pre>\n<pre><span> 555:  <\/span>??<\/pre>\n<pre><span> 556:  <\/span> WshShell.Run  sFullCall,1,<span>False<\/span> <\/pre>\n<pre><span> 557:  <\/span> <span>Set<\/span> WshShell = <span>Nothing<\/span> <\/pre>\n<pre><span> 558:  <\/span> WScript.Quit <\/pre>\n<pre><span> 559:  <\/span><span>End<\/span> <span>If<\/span> <\/pre>\n<pre><span> 560:  <\/span><span>End<\/span> <span>Sub<\/span> <\/pre>\n<pre><span> 561:  <\/span>??<\/pre>\n<pre><span> 562:  <\/span><span>=======================================================================<\/span><\/pre>\n<pre><span> 563:  <\/span><span> *** MAIN **************************************<\/span><\/pre>\n<pre><span> 564:  <\/span><span>=======================================================================<\/span><\/pre>\n<pre><span> 565:  <\/span>??<\/pre>\n<pre><span> 566:  <\/span>??<\/pre>\n<pre><span> 567:  <\/span>??<\/pre>\n<pre><span> 568:  <\/span>??<\/pre>\n<pre><span> 569:  <\/span><span>set<\/span> output = wscript.stdout<\/pre>\n<pre><span> 570:  <\/span>bVerbose = arguments.Named.Exists(<span>\"verbose\"<\/span>) <span>Or<\/span> arguments.Named.Exists(<span>\"v\"<\/span>)<\/pre>\n<pre><span> 571:  <\/span>??<\/pre>\n<pre><span> 572:  <\/span><span>Call<\/span> EchoUsage()<\/pre>\n<pre><span> 573:  <\/span><span>Call<\/span> CheckArgs()<\/pre>\n<pre><span> 574:  <\/span>??<\/pre>\n<pre><span> 575:  <\/span><span>Set<\/span> ofso = CreateObject(<span>\"Scripting.FileSystemObject\"<\/span>)<\/pre>\n<pre><span> 576:  <\/span><span>Set<\/span> owdo = CreateObject(<span>\"Word.Application\"<\/span>)<\/pre>\n<pre><span> 577:  <\/span><span>Set<\/span> owdocs = owdo.Documents<\/pre>\n<pre><span> 578:  <\/span>??<\/pre>\n<pre><span> 579:  <\/span>sFolder= <span>\"\"<\/span><\/pre>\n<pre><span> 580:  <\/span>??<\/pre>\n<pre><span> 581:  <\/span><span>if<\/span> <span>not<\/span> arguments.Named.Exists(<span>\"dir\"<\/span>) <span>then<\/span><\/pre>\n<pre><span> 582:  <\/span>   <span>Single Document Conversion<\/span><\/pre>\n<pre><span> 583:  <\/span>   <span>Call<\/span> DOC2PDF( arguments.Unnamed.Item(0), arguments.Named.Item(<span>\"o\"<\/span>) )<\/pre>\n<pre><span> 584:  <\/span><span>else<\/span><\/pre>\n<pre><span> 585:  <\/span>   <span>Batch Conversion<\/span><\/pre>\n<pre><span> 586:  <\/span>   sFolder = arguments.Named.Item(<span>\"dir\"<\/span>)<\/pre>\n<pre><span> 587:  <\/span>   <span>if<\/span> right(sFolder,1) = <span>\"\\\"<\/span> <span>then<\/span><\/pre>\n<pre><span> 588:  <\/span>    sFolder = left(sFolder, Len(sFolder)-1)<\/pre>\n<pre><span> 589:  <\/span>   <span>end<\/span> <span>if<\/span> <\/pre>\n<pre><span> 590:  <\/span>??<\/pre>\n<pre><span> 591:  <\/span>   <span>if<\/span> <span>Not<\/span> oFso.FolderExists(sFolder)  <span>then<\/span><\/pre>\n<pre><span> 592:  <\/span>      output.WriteLine  <span>\"Error: Input Folder for Batch Processing does not exist!\"<\/span><\/pre>\n<pre><span> 593:  <\/span>   <span>else<\/span><\/pre>\n<pre><span> 594:  <\/span><span>      WScript.Echo sFolder & \"\\\" & arguments.Unnamed.Item(0)<\/span><\/pre>\n<pre><span> 595:  <\/span>       aFiles = ListDir(sFolder & <span>\"\\\"<\/span> & arguments.Unnamed.Item(0))<\/pre>\n<pre><span> 596:  <\/span>       <span>If<\/span> UBound(aFiles) = -1 <span>then<\/span><\/pre>\n<pre><span> 597:  <\/span>          output.WriteLine  <span>\"No files found.\"<\/span><\/pre>\n<pre><span> 598:  <\/span>       <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 599:  <\/span>       <span>For<\/span> <span>Each<\/span> FileName <span>In<\/span> aFiles <\/pre>\n<pre><span> 600:  <\/span>          <span>Call<\/span> DOC2PDF(FileName,<span>\"\"<\/span>)  <\/pre>\n<pre><span> 601:  <\/span>       <span>Next<\/span><\/pre>\n<pre><span> 602:  <\/span>   <span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 603:  <\/span>??<\/pre>\n<pre><span> 604:  <\/span><span>end<\/span> <span>if<\/span><\/pre>\n<pre><span> 605:  <\/span>??<\/pre>\n<pre><span> 606:  <\/span>owdo.Quit WdDoNotSaveChanges<\/pre>\n<pre><span> 607:  <\/span><span>Set<\/span> owdo = <span>Nothing<\/span><\/pre>\n<pre><span> 608:  <\/span><span>Set<\/span> arguments = <span>Nothing<\/span><\/pre>\n<pre><span> 609:  <\/span><span>Set<\/span> oFso = <span>Nothing<\/span><\/pre>\n<pre><span> 610:  <\/span>        <\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>It started with a script by Michael Suodenjoki called &#8220;docx2pdf.vbs&#8221; that lets you convert individual Word 2007 documents to PDF. It is possible to use it to process a batch of files, such as all documents in a specific directory, by using (programming) another sophisticated MS DOS batch script, but that is a pain in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,3],"tags":[],"class_list":["post-104","post","type-post","status-publish","format-standard","hentry","category-internet-marketing","category-tools"],"_links":{"self":[{"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/posts\/104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":0,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.roysac.com\/blog\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}