Hello!
I am not trained in batch programming...
In my Windows XP Pro SP3 I sometimes noticed that normal.dot was changed in a way I didn't want.
So I wrote this batch to always load a backed-up version of normal.dot when starting Winword 2003:
@echo off
del D:\Docume~1\janeri~1\Applic~1\Micros~1\Templa~1\~$Normal.dot /A:H
copy D:\normal.dot E:\Office\Office~1\Templa~1\1033\ /Y
copy D:\normal.dot D:\Docume~1\janeri~1\Applic~1\Micros~1\Templa~1 /Y
start E:\Office\Office~1\OFFICE11\WINWORD.EXE
cls
exit
Office 2003 is in E:\Office..., my WinXP in D: (for certain reasons) and the back-up as well as the batch are in D:
This works fine.
But -as expected - when I mark a doc file and choose "Open with" and there pick my batch file, it just opens Winword but not with that doc file displayed.
Somehow I would have to transfer the path with the file to append after WINWORD.EXE above.
I would very much appreciate your help!
Open doc file in Winword via a batch file
Moderator: DosItHelp
Re: Open doc file in Winword via a batch file
Well, your batch file opens Word but without any argument. How should Word know which document you want to open?
OK. The solution should be simple. If you choose your batch file by "Open with" context, then your document is given as argument to the batch file. You will find it as %1. So change the command line:
Regards
aGerman
OK. The solution should be simple. If you choose your batch file by "Open with" context, then your document is given as argument to the batch file. You will find it as %1. So change the command line:
Code: Select all
start E:\Office\Office~1\OFFICE11\WINWORD.EXE %1
Regards
aGerman
Re: Open doc file in Winword via a batch file
That works just fine!
Thanks a lot!
batchelor
Thanks a lot!
batchelor
Re: Open doc file in Winword via a batch file
This file, a bit modified, works fine in my XP Pro.
But a friend of mine tried it in Windows 7 and it didn't work well, even written without the "traditonal" 8+3 format:
@echo off
if exist C:\"Documents and Settings"\"[your name]"\"Application Data"\"Microsoft"\"Templates"\~$Normal.dot del C:\"Documents and Settings"\"[your name]"\"Application Data"\"Microsoft"\"Templates"\~$Normal.dot /A:H
if exist C:\"Program Files"\"Microsoft Office"\Office11\~$Normal.dot del C:\"Program Files"\"Microsoft Office"\Office11\~$Normal.dot /A:H
copy C:\normal.dot C:\"Documents and Settings"\"[your name]"\"Application Data"\"Microsoft"\"Templates" /Y
copy C:\normal.dot C:\"Program Files"\"Microsoft Office"\Office11\~$Normal.dot /Y
start C:\"Program Files"\"Microsoft Office"\Office11\WINWORD.EXE %1
cls
exit
(The "if exist" is, of course, not necessary, but added as a extra security against erasing a wrong file in case something doesn't work correctly. A normal.dot as I want it is backed up in C:\.)
Is there some difference between how XP and 7 run batch files?
But a friend of mine tried it in Windows 7 and it didn't work well, even written without the "traditonal" 8+3 format:
@echo off
if exist C:\"Documents and Settings"\"[your name]"\"Application Data"\"Microsoft"\"Templates"\~$Normal.dot del C:\"Documents and Settings"\"[your name]"\"Application Data"\"Microsoft"\"Templates"\~$Normal.dot /A:H
if exist C:\"Program Files"\"Microsoft Office"\Office11\~$Normal.dot del C:\"Program Files"\"Microsoft Office"\Office11\~$Normal.dot /A:H
copy C:\normal.dot C:\"Documents and Settings"\"[your name]"\"Application Data"\"Microsoft"\"Templates" /Y
copy C:\normal.dot C:\"Program Files"\"Microsoft Office"\Office11\~$Normal.dot /Y
start C:\"Program Files"\"Microsoft Office"\Office11\WINWORD.EXE %1
cls
exit
(The "if exist" is, of course, not necessary, but added as a extra security against erasing a wrong file in case something doesn't work correctly. A normal.dot as I want it is backed up in C:\.)
Is there some difference between how XP and 7 run batch files?
Re: Open doc file in Winword via a batch file
Code: Select all
@echo off
set ndot1=%APPDATA%\Microsoft\Templates\~$Normal.dot
set ndot2=%ProgramFiles%\Microsoft Office\Office11\~$Normal.dot
if exist "%ndot1%" del "%ndot1%" /A:H && copy C:\normal.dot "%ndot1%" /Y
if exist "%ndot2%" del "%ndot2%" /A:H && copy C:\normal.dot "%ndot2%" /Y
copy C:\normal.dot "%APPDATA%\Microsoft\Templates" /Y
start "%~1" "%ProgramFiles%\Microsoft Office\Office11\WINWORD.EXE" "%~1"
P.S. not tested
Last edited by amel27 on 25 Sep 2010 04:43, edited 2 times in total.
Re: Open doc file in Winword via a batch file
Thanks!
But it seems that I need to explain why I delete ~$Normal.dot. This is a backup of normal.dot that Word makes when running and that normally disappears when Word is terminated.
It in rare cases happens that it is not deleted (for example, after a crash), and if not, it may lead to a modification of normal.dot next time Word is run.
So before I copy my backup of normal.dot to its proper location, I check if there is an undeleted ~$Normal.dot there and, in that case, delete it.
The next step is then to copy my backed-up normal.dot (being as I want to have it) to where it belongs.
This all works fine in my XP Pro but apparently not as well in Win7 ...
But it seems that I need to explain why I delete ~$Normal.dot. This is a backup of normal.dot that Word makes when running and that normally disappears when Word is terminated.
It in rare cases happens that it is not deleted (for example, after a crash), and if not, it may lead to a modification of normal.dot next time Word is run.
So before I copy my backup of normal.dot to its proper location, I check if there is an undeleted ~$Normal.dot there and, in that case, delete it.
The next step is then to copy my backed-up normal.dot (being as I want to have it) to where it belongs.
This all works fine in my XP Pro but apparently not as well in Win7 ...
Re: Open doc file in Winword via a batch file
for instance %APPATH% is different in XP (c:\Documents and Settings\) and Win7 (c:\Users\)batchelor wrote:This all works fine in my XP Pro but apparently not as well in Win7 ...
P.S. previous post edited
Re: Open doc file in Winword via a batch file
Thanks, I will suggest to my friend to try this.