Index: /main/trunk/binaries/windows/bin/docx2html.vbs
===================================================================
--- /main/trunk/binaries/windows/bin/docx2html.vbs	(revision 24165)
+++ /main/trunk/binaries/windows/bin/docx2html.vbs	(revision 24166)
@@ -1,18 +1,46 @@
 Option Explicit
 
-'args = WScript.Arguments.Count
-'If args < 2 then
-'  WScript.Echo usage: args.vbs argument [input docx path] [output html path]
-'  WScript.Quit
-'end If
-'WScript.Echo WScript.Arguments.Item(0)
-'WScript.Echo WScript.Arguments.Item(1)
+' http://www.robvanderwoude.com/vbstech_automation_word.php
+' http://www.nilpo.com/2008/06/windows-scripting/reading-word-documents-in-wsh/ - for grabbing just the text (cleaned of Word mark-up) from a doc(x)
+' http://msdn.microsoft.com/en-us/library/3ca8tfek%28v=VS.85%29.aspx - VBScript Functions (CreateObject etc)
 
-Doc2HTML WScript.Arguments.Item(0),WScript.Arguments.Item(1)
-' In terminal, run as: > docx2html.vbs C:\fullpath\to\input.docx C:\fullpath\to\output.html
+' Error Handling:
+' http://blogs.msdn.com/b/ericlippert/archive/2004/08/19/error-handling-in-vbscript-part-one.aspx
+' http://msdn.microsoft.com/en-us/library/53f3k80h%28v=VS.85%29.aspx 
 
 
-' http://www.robvanderwoude.com/vbstech_automation_word.php
-' http://www.nilpo.com/2008/06/windows-scripting/reading-word-documents-in-wsh/
+' To Do:
+' +1. error output on bad input to this file. And commit.
+' +1b. Active X error msg when trying to convert normal *.doc: only when windows scripting is on and Word not installed.
+' +1c. Make docx accepted by default as well. Changed WordPlugin.
+' 2. Try converting from other office types (xlsx, pptx) to html. They may use other constants for conversion filetypes
+' 3. gsConvert.pl's any_to_txt can be implemented for docx by getting all the text contents. Use a separate subroutine for this. Or use wdFormatUnicodeText as outputformat.
+' 4. Try out this script on Windows 7 to see whether WSH is active by default, as it is on XP and Vista.
+' 5. What kind of error occurs if any when user tries to convert docx on a machine with an old version of Word (pre-docx/pre-Word 2007)?
+' 6. Ask Dr Bainbridge whether this script can or shouldn't replace word2html, since this launches all version of word as well I think.
+
+
+' gsConvert.pl expects error output to go to the console's STDERR 
+' for which we need to launch this vbs with "CScript //Nologo" '(cannot use WScript if using StdErr
+' and //Nologo is needed to repress Microsoft logo text output which messes up error reporting)
+' http://www.devguru.com/technologies/wsh/quickref/wscript_StdErr.html
+Dim objStdErr, args
+Set objStdErr = WScript.StdErr
+
+args = WScript.Arguments.Count
+If args < 2 then
+  'WScript.Echo Usage: args.vbs argument [input docx path] [output html path]
+  objStdErr.Write ("ERROR. Usage: CScript //Nologo " & WScript.ScriptName & " [input office doc path] [output html path]" & vbCrLf)
+  WScript.Quit
+end If
+
+' Now run the conversion subroutine
+Doc2HTML WScript.Arguments.Item(0),WScript.Arguments.Item(1)
+	' In terminal, run as: > docx2html.vbs C:\fullpath\to\input.docx C:\fullpath\to\output.html
+	' In terminal, run as: > CScript //Nologo docx2html.vbs C:\fullpath\to\input.docx C:\fullpath\to\output.html
+	' if you want echoed error output to go to console (instead of creating a popup) and to avoid 2 lines of MS logo.
+	' Will be using WScript.StdErr object to make error output go to stderr of CScript console (can't launch with WScript).
+	' http://www.devguru.com/technologies/wsh/quickref/wscript_StdErr.html
+
 
 Sub Doc2HTML( inFile, outHTML )
@@ -55,10 +83,19 @@
     Const wdFormatXMLTemplateMacroEnabled     = 15
     Const wdFormatXPS                         = 18
-
+	
     ' Create a File System object
     Set objFSO = CreateObject( "Scripting.FileSystemObject" )
 
-    ' Create a Word object
+    ' Create a Word object. Exit with error msg if not possible (such as when Word is not installed)
+	On Error Resume Next
     Set objWord = CreateObject( "Word.Application" )
+	If CStr(Err.Number) = 429 Then	' 429 is the error code for "ActiveX component can't create object" 
+									' http://msdn.microsoft.com/en-us/library/xe43cc8d%28v=VS.85%29.aspx		
+		'WScript.Echo "Microsoft Word cannot be found -- document conversion cannot take place. Error #" & CStr(Err.Number) & ": " & Err.Description & "." & vbCrLf
+		objStdErr.Write ("ERROR: Windows-scripting failed. Document conversion cannot take place:" & vbCrLf) 
+		objStdErr.Write ("   Microsoft Word cannot be found or cannot be launched. (Error #" & CStr(Err.Number) & ": " & Err.Description & "). " & vbCrLf)		
+		objStdErr.Write ("   For converting the latest Office documents, install OpenOffice and Greenstone's OpenOffice extension. (Turn it on and turn off windows-scripting.)" & vbCrLf) 
+		Exit Sub
+	End If
 
     With objWord
@@ -71,5 +108,6 @@
             strFile = objFile.Path
         Else
-            WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
+            'WScript.Echo "FILE OPEN ERROR: The file does not exist" & vbCrLf
+            objStdErr.Write ("ERROR: Windows-scripting failed. Cannot open " & inFile & ". The file does not exist. ")
             ' Close Word
             .Quit
@@ -79,5 +117,4 @@
         'outHTML = objFSO.BuildPath( objFile.ParentFolder, _
         '          objFSO.GetBaseName( objFile ) & ".html" )
-	'outHTML = outFile
 
         ' Open the Word document
Index: /main/trunk/greenstone2/bin/script/gsConvert.pl
===================================================================
--- /main/trunk/greenstone2/bin/script/gsConvert.pl	(revision 24165)
+++ /main/trunk/greenstone2/bin/script/gsConvert.pl	(revision 24166)
@@ -786,15 +786,25 @@
     my ($input_filename, $output_filestem) = @_;
 
-    my $vbScript = &util::filename_cat($ENV{'GSDLHOME'}, "bin",
-				       $ENV{'GSDLOS'}, "word2html");
+	# build up the path to the doc-to-html conversion tool we're going to use
+	my $vbScript = &util::filename_cat($ENV{'GSDLHOME'}, "bin", $ENV{'GSDLOS'});
 
     if ($ENV{'GSDLOS'} =~ m/^windows$/i) {
-	# if windows scripting with docx input, use new VBscript
-	if($input_filename =~ m/docx$/i) {
-	    $vbScript = "docx2html.vbs"; 
-	} else { # use the usual word2html conversion VB executable
-	    $vbScript = "word2html";
-	}
-    }
+		# if windows scripting with docx input, use new VBscript to get the local Word install (if
+		# any) to do the conversion, since docX can't be processed by word2html's windows_scripting
+		
+		if($input_filename =~ m/docx$/i) {	# need to use full path to docx2html script, 
+											# else script launch fails when there are error msgs
+			$vbScript = &util::filename_cat($vbScript, "docx2html.vbs"); 
+			$vbScript = "CScript //Nologo \"$vbScript\"";	# launche with CScript for error output in STDERR
+															# //Nologo flag avoids Microsoft's opening/logo msgs
+		} 
+		else {	# old doc versions. use the usual VB executable word2html for the
+				# conversion. Doesn't need full path, since bin\windows is on PATH			
+			$vbScript = "word2html"; #$vbScript = "\"".&util::filename_cat($vbScript, "word2html")."\"";
+		}
+    } 
+	else { # not windows
+		$vbScript = "\"".&util::filename_cat($vbScript, "word2html")."\"";
+	}
 
     if (-e "$output_filestem.html") {
@@ -812,7 +822,9 @@
 
     # redirecting STDERR
-    $cmd .= " 2> \"$output_filestem.err\""
-	if ($ENV {'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000);
-    
+	
+	$cmd .= " 2> \"$output_filestem.err\""
+		if ($ENV {'GSDLOS'} !~ m/^windows$/i || $is_winnt_2000);    
+	#print STDERR "@@@@@@@@@ cmd=$cmd\n";
+	
     # execute the command
     $!=0;
@@ -822,5 +834,5 @@
 	if (-s "$output_filestem.err") {
 	    open (ERRFILE, "<$output_filestem.err");
-	    
+		
 	    my $write_to_fail_log=0;
 	    if ($faillogfile ne "" && defined(open(FAILLOG,">>$faillogfile")))
Index: /main/trunk/greenstone2/perllib/plugins/WordPlugin.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugins/WordPlugin.pm	(revision 24165)
+++ /main/trunk/greenstone2/perllib/plugins/WordPlugin.pm	(revision 24166)
@@ -239,5 +239,5 @@
 	return q^(?i)\.(doc|dot|docx|odt|wpd)$^;
     }
-    return q^(?i)\.(doc|dot)$^;
+    return q^(?i)\.(docx?|dot)$^;
 }
 
