Skip to main content

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
Perhaps a security setting in Win 2003 is causing this, I'm not sure. Perhaps there are slight differences in object model methods and properties between Office XP and Office 2003 effecting things. Again, not sure.

However, a different approach would avoid this all together. For instance, turn word visibility off when creating new word file and instead of leaving word open, close your doc with Close() and terminate word by using the word app Quite() method before destroying the word app handle. Then, use C$SYSTEM to open the new word file. The windows shell will open the associated program for your new word file which should be MS Word. This would be a cleaner break between your cobol app and ms word and should work for all current word versions. Just a thought.

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
Perhaps a security setting in Win 2003 is causing this, I'm not sure. Perhaps there are slight differences in object model methods and properties between Office XP and Office 2003 effecting things. Again, not sure.

However, a different approach would avoid this all together. For instance, turn word visibility off when creating new word file and instead of leaving word open, close your doc with Close() and terminate word by using the word app Quite() method before destroying the word app handle. Then, use C$SYSTEM to open the new word file. The windows shell will open the associated program for your new word file which should be MS Word. This would be a cleaner break between your cobol app and ms word and should work for all current word versions. Just a thought.

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
Dan,
thanks for the tips. They were very usefull. I still had to change something in your solution to get rid of the annoying messages. I performed a "Quit(wdDoNotSaveChanges)". Without the "wdDoNotSaveChanges"-option word 2003 still gave the messages.
The use of the C$SYSTEM doesn't open the associated program so I had to put the complete path to winword.exe in the C$SYSTEM command.
p.s.
Now that I'm writing this message I see that I didn't use the close command to close the word-document first. Maybe this triggered the messages but this doesn't matter anymore at this moment.

Thanks
Jack Magielse

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
i just read that you handled the problem.
But i think there is another way to fix it, so i think it?s a good idea to post this way too.

i had nearly the same problem in a vba project. the way that worked for me was to write this lines just before the close command:

NormalTemplate.Saved = True
ActiveDocument.AttachedTemplate.Saved = True

the cobol command could look like this (not tested it and new to ActiceX in Cobol):
MODIFY wrdDoc NormalTemplate::saved("true")

to do the second line you maybe will need another handle of the activeDocument object.


maybe someone will find this useful too .. maybe i?m wrong.


One 2 things more to say:
- english is not my foreign language and i am writing without any translation program, so please be kind to me ;)
- This is my first post here .. so tell me if something is wrong

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
The solution from SliverHH worked. I searched on the internet and found that this is also the solution Microsoft offers for this known problem. So I changed my program again. I removed the quit and replaced it with "MODIFY wrdApp NormalTemplate::Saved = 1." before I destroyed all the handles. This way I don'y have to start word twice which is much faster.
I include the program so anybody who thinks it's helpfull and has the right DEF-copy files can use it.

Thanks again Dan and SliverHH

Jack Magielse

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
The solution from SliverHH worked. I searched on the internet and found that this is also the solution Microsoft offers for this known problem. So I changed my program again. I removed the quit and replaced it with "MODIFY wrdApp NormalTemplate::Saved = 1." before I destroyed all the handles. This way I don'y have to start word twice which is much faster.
I include the program so anybody who thinks it's helpfull and has the right DEF-copy files can use it.

Thanks again Dan and SliverHH

Jack Magielse

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
Great job Silver and jmag! This is why the forums are a valuable resource. :D

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
I echo DanM's sentiments. Have been looking for a simple solution to filling merge fields. Several members have proposed solutions but all seem so much more cumbersome. I have a project that needs to create real estate sales contracts and addendums from data stored in vision files. I think this is best handled by merging the data with forms created in word. Anyway, a big thanks to all who have helped.

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
SliverHH is right on target.

I just thought that I should mention that this undesireable behavior of MS Word is in fact addressed in my MSWordMailMerge demo, although not particularly emphasized.

Great work guys, you are all outstanding contributors!

[Migrated content. Thread originally posted on 03 November 2004]

I start word through cobol open a file save it and leave word open so the user can make changes/print/email/etc.. When I do this on a client with word 2002 there is nothing wrong. When I do this on a client with word 2003 and I close word manually I get all sort of anoying question about changes made in normal.dot and if I want to save them. How can I avoid this? The code I'm using is as follows:
CREATE APPLICATION OF WORD
HANDLE IN wrdApp.
MODIFY wrdApp @Visible = 1.
MODIFY wrdApp Documents::Open(
BY NAME FileName COBWORD-OPEN-BESTNAAM)
GIVING wrdDoc.
INQUIRE wrdDoc Fields IN wrdFields.
INQUIRE wrdFields Count IN WS-AANT-VELDEN.
PERFORM VARYING WS-IND FROM 1 BY 1
UNTIL WS-IND > WS-AANT-VELDEN
MODIFY wrdDoc Fields::Item(WS-IND)
GIVING wrdField
INQUIRE wrdField Type IN WS-TYPE
MOVE SPACE TO WS-NAAM
INQUIRE wrdField Result::Text IN WS-NAAM
IF WS-TYPE = 59
MODIFY wrdField Result::Text = WS-IND
END-IF
END-PERFORM.
MODIFY wrdDoc SaveAs(
BY NAME FileName COBWORD-SAVEAS-BESTNAAM).
APP-MAIN-900.
SET VANUIT-AFSLUITEN TO TRUE.
DESTROY wrdSelection.
DESTROY wrdField.
DESTROY wrdFields.
DESTROY wrdDoc.
DESTROY wrdApp.
SliverHH is right on target.

I just thought that I should mention that this undesireable behavior of MS Word is in fact addressed in my MSWordMailMerge demo, although not particularly emphasized.

Great work guys, you are all outstanding contributors!