[solved]converting

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

[solved]converting

#1 Post by princesstwi » 09 Dec 2013 08:48

i was wondering does anyone know a batch file code that will convert a windows docx file to a doc file help would be apreciated
Last edited by princesstwi on 10 Dec 2013 10:17, edited 1 time in total.

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: converting

#2 Post by npocmaka_ » 09 Dec 2013 09:13

Here are the Word saving constants -> http://msdn.microsoft.com/en-us/library ... 39952.aspx
You can check this thread and change the save constant to 0 -> viewtopic.php?f=3&t=4755

princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

Re: converting

#3 Post by princesstwi » 09 Dec 2013 09:47

which is the save constant
note im on a vista

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: converting

#4 Post by npocmaka_ » 09 Dec 2013 09:59

The saving constant is passed as the third parameter to the vbscript.Here's ready to use docxToDoc converter .Should be saved as .bat

Code: Select all

'>nul 2>&1|| @copy /Y %windir%\System32\doskey.exe .\'.exe >nul
'&&@echo off && cls &&goto :end_vbs
 
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = FALSE

'Open doc for reading
Set WordDoc = WordApp.Documents.Open(WScript.Arguments.Item(0),true)

'wdFormatText 2
'wdFormatUnicodeText 7
'wdFormatDocument 0
format = CInt(WScript.Arguments.Item(2) )
WordDoc.SaveAs WScript.Arguments.Item(1) ,format
WordDoc.Close()
WScript.Quit

:end_vbs

'& if "%~1" equ "-help" echo %~n0 word_document [ destination ] && exit /b 0
'& if "%~1" equ "" echo word document not given & exit /b 1
'& if not exist "%~f1" echo word document does not exist & exit /b 2
'& if "%~2" equ "" ( set "save_as=%~n1.doc") else ( set "save_as=%~2")
'& if  exist "%~f2" del /s /q "%~f2"
'&  set "format=0"
'& taskkill /im winword* /f >nul 2>&1
'& cscript /nologo /E:vbscript %~f0 "%~f1" "%save_as%" %format%
'& pause
'& rem del /q .\'.exe

princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

Re: converting

#5 Post by princesstwi » 09 Dec 2013 10:05

ok i open it it runs, closes and nothing has changed
:|

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: converting

#6 Post by npocmaka_ » 09 Dec 2013 10:10

what parameters did you passed to the script?

it must be called like this:

Code: Select all

call docxToDoc.bat "c:\SomeDoc.docx" "c:\converted.doc"


and this should create a c:\converted.doc file.

princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

Re: converting

#7 Post by princesstwi » 09 Dec 2013 10:13

what do you mean it didnt ask me to type anything it just opened ran code real quick and closed

im sorry if im missunderstanding i am new to all batch

princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

Re: converting

#8 Post by princesstwi » 09 Dec 2013 11:42

that batch doesnt work for me please help i need to convert some school assignments please help


i am on a windows vista

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: converting

#9 Post by npocmaka_ » 09 Dec 2013 12:36

here's a prompting version:

Code: Select all

'>nul 2>&1|| @copy /Y %windir%\System32\doskey.exe .\'.exe >nul
'&&@echo off && cls &&goto :end_vbs
 
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = FALSE

'Open doc for reading
Set WordDoc = WordApp.Documents.Open(WScript.Arguments.Item(0),true)

'wdFormatText 2
'wdFormatUnicodeText 7
'wdFormatDocument 0
format = CInt(WScript.Arguments.Item(2) )
WordDoc.SaveAs WScript.Arguments.Item(1) ,format
WordDoc.Close()
WScript.Quit

:end_vbs


'& set /p source=Path to the .DOCX file:
'& set /p dest=Destination file:
'& for %%p in  ("%source%") do set "source=%%~dpfnxsp"
'& set "dest=%~dp0\%dest%"
'& set "format=0"
'& taskkill /im winword* /f >nul 2>&1
'& cscript /nologo /E:vbscript "%~f0" "%source%" "%dest%" %format%
'& pause
'& rem del /q .\'.exe


Works on my machine .It's vista too...
Last edited by npocmaka_ on 09 Dec 2013 14:31, edited 1 time in total.

princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

Re: converting

#10 Post by princesstwi » 09 Dec 2013 12:47

so the path to the docx would be if its on the desktop c:\Users\user\Desktop\example.docx

and the path for the converted file would be c:\Users\user\Desktop\converted.doc

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: converting

#11 Post by npocmaka_ » 09 Dec 2013 12:59

it will create a doc file in the same directory.If you want to use full path delete this line:
'& set "dest=%~dp0\%dest%"


Probably will be better if you automize the file processing so you'll not have to set destination and source manually.

princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

Re: converting

#12 Post by princesstwi » 09 Dec 2013 13:08

path to docx file: C:\Users\user\Desktop\Walking Dead Dialectical Journal.docx
destination file: C:\Users\user\Desktop\it works.doc or i put yes.doc

it comes up with this C:\Users\user\Desktop\docxToDoc.bat<8,1> Microsoft word: command failed

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: converting

#13 Post by npocmaka_ » 09 Dec 2013 14:33

I've changed the script to use a short path , to minimize the problems with empty spaces.Use it like this:

path to docx file: C:\Users\user\Desktop\Walking Dead Dialectical Journal.docx
destination file: yes.doc


and it should create yes.doc in the same directory as the batch file.And be sure that the walking dead file exists.

princesstwi
Posts: 26
Joined: 03 Dec 2013 12:34

Re: converting

#14 Post by princesstwi » 10 Dec 2013 08:13

ok i did what you said and on some it will convert but still be random letters and symbols but others it will come up with this error msg C:\Users\user\Desktop\docxToDoc.bat<8,1> Microsoft word: command failed


i am trying to convert word 2010 to word 2000

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: converting

#15 Post by npocmaka_ » 10 Dec 2013 08:16

what symbols? May be some of them could be escaped...

Post Reply