Skip to main content

[archive] Word control and template selection.

  • January 30, 2009
  • 12 replies
  • 0 views

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.

12 replies

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
What is the name of the method you use to run the dialog?

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
What is the name of the method you use to run the dialog?

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
Hi,

I used the following sample (found on the forum and chanced it a little)

In this sample I used

MODIFY WrdApp Documents::Add(
BY NAME Template TemplateNaam
BY NAME NewTemplate 0
BY NAME DocumentType 0
BY NAME Visible 1)
GIVING WrdDoc.

To open a word document.


If possible I want to select first a template with the template dialog box from word.

I looked in de def file from the OFFICE11\\MSWORD.OLB object if there is a class that I could use. I've also looked at the Microsoft msdn if there was a sample for the MSWORD.OLB (I'm not so good in the vb stuff) .

Perhaps someone can tell me which method I should use (or even better has a sample how to call the template dialog box from word).

Thanks

Ed


IDENTIFICATION DIVISION.
PROGRAM-ID. ExcelArray.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.

COPY "Microsoft Word 11.def".
.
DATA DIVISION.

WORKING-STORAGE SECTION.

77 WrdApp HANDLE OF APPLICATION.
77 WrdDoc HANDLE OF DOCUMENT.

01 WS-AANT-VELDEN PIC 9(03).
01 WS-IND PIC 9(03).
01 WS-TYPE PIC 9(04).
01 WS-NAAM PIC X(32).
01 WS-DOCUMENT-NAAM PIC X(64).

01 text-buffer pic x(32768).
01 text-lengte pic 9(06).

01 TemplateNaam PIC X(80) VALUE
"D:\\WordTest\\test.dot".

PROCEDURE DIVISION.
Main SECTION.

*Create application of word
CREATE Application OF Word
HANDLE IN WrdApp.

*Show Word, this is very handy when debugging, as you will see
*everything as it happens. In production you would probably not
*set it visible. Word is by default hidden when invoked through OLE.

MODIFY wrdApp @Visible = 1.

*Create the initial document place holder.
*Documents.Add NewTemplate:=False, DocumentType:=0

MODIFY WrdApp Documents::Add(
BY NAME Template TemplateNaam
BY NAME NewTemplate 0
BY NAME DocumentType 0
BY NAME Visible 1)
GIVING WrdDoc.


*Close the merged document

MODIFY wrdDoc @Close().

*Terminate Word.

MODIFY wrdApp Quit().

*Clean up

IF WrdDoc > 0
DESTROY wrdDoc.
IF WrdApp > 0
DESTROY wrdApp.

GOBACK.
ENDS.
EXIT.

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
Turns out there are two ways to deal with this, you can either show the generic dialog:

           create @Application of @Word handle in word-app.           
           modify word-app @visible = 1.
           modify word-app @Dialogs::Item(wdDialogFileOpen)
               giving word-dlg
           modify word-dlg show()


However, the method to retrieve the chosen name and/or set filters is via invoking runtime dependent properties, unforunately ACUCOBOL-GT does not support this.

The other method is to use the Application.FileDialog property, however, the catch with this one, is that the definition file does not contain the class, kind of odd really. But this one seem to be the real thing for your case, here is an example: http://support.microsoft.com/kb/824272
It is supposed to be a member of the Microsoft Office Object Model, but from where to generate that .def file? I have no clue.

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
Turns out there are two ways to deal with this, you can either show the generic dialog:

           create @Application of @Word handle in word-app.           
           modify word-app @visible = 1.
           modify word-app @Dialogs::Item(wdDialogFileOpen)
               giving word-dlg
           modify word-dlg show()


However, the method to retrieve the chosen name and/or set filters is via invoking runtime dependent properties, unforunately ACUCOBOL-GT does not support this.

The other method is to use the Application.FileDialog property, however, the catch with this one, is that the definition file does not contain the class, kind of odd really. But this one seem to be the real thing for your case, here is an example: http://support.microsoft.com/kb/824272
It is supposed to be a member of the Microsoft Office Object Model, but from where to generate that .def file? I have no clue.

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
Thanks for your reply, With it I found the following solution : :)


create @Application of @Word handle in word-app.
modify word-app @visible = 1.
modify word-app @Dialogs::Item(wdDialogFileNew)
giving word-dlg
modify word-dlg show()


The wdDialogFileNew automatically gives the dialog open box with the templates (same as if you open a new document in word).

The modify word-dlg show() stops the cobol program waiting for an action in the dialog box.

After this :
MODIFY word-app Documents::Item(1)
GIVING word-doc. (this is the HANDLE OF DOCUMENT)

If I have a handle the users did create a new document/template. I can use this handle to process the document.
If I don't have a handle, the user closed without a document.

Note : if there was no document selected the handle returns 3 in stead of 0, but this seems no problem.

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
Thanks for your reply, With it I found the following solution : :)


create @Application of @Word handle in word-app.
modify word-app @visible = 1.
modify word-app @Dialogs::Item(wdDialogFileNew)
giving word-dlg
modify word-dlg show()


The wdDialogFileNew automatically gives the dialog open box with the templates (same as if you open a new document in word).

The modify word-dlg show() stops the cobol program waiting for an action in the dialog box.

After this :
MODIFY word-app Documents::Item(1)
GIVING word-doc. (this is the HANDLE OF DOCUMENT)

If I have a handle the users did create a new document/template. I can use this handle to process the document.
If I don't have a handle, the user closed without a document.

Note : if there was no document selected the handle returns 3 in stead of 0, but this seems no problem.

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
Glad it worked out :-)

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
When I start the word active-x control on a windows xp machine, the word object got the focus and is displayed over my cobol application screen. (So the user can immediately use the word object).

The same program on vista result in word on the background, so the user has to set the focus first on word by the taskbar. Even when I use the MODIFY word-app @Activate() the word application stay?s on the background. The only difference now is a short blinking from the word application in the task bar. Is there a way to bring it to the foreground in Vista.

Thanks,
Ed

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
When I start the word active-x control on a windows xp machine, the word object got the focus and is displayed over my cobol application screen. (So the user can immediately use the word object).

The same program on vista result in word on the background, so the user has to set the focus first on word by the taskbar. Even when I use the MODIFY word-app @Activate() the word application stay?s on the background. The only difference now is a short blinking from the word application in the task bar. Is there a way to bring it to the foreground in Vista.

Thanks,
Ed

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
Hm... Sounds like a change of behavior from Windows' side.
I know you can do it with the API and iterating through the window list eventually using the api function SetForegroundWindow, but you probably want to avoid that. What about minimizing your app, prior to making word start/visible, have you tried that?
I also see that the Application object has a method Activate, but whether that will do, I have no idea.

[Migrated content. Thread originally posted on 29 January 2009]

Hi,

Is there perhaps anyone who has experience in how to select a available template in word with the template dialog box. Instead of the documents::Add, I want (if possible) to let the user select one of the available templates in word first.

Greetings,

Ed.
Hm... Sounds like a change of behavior from Windows' side.
I know you can do it with the API and iterating through the window list eventually using the api function SetForegroundWindow, but you probably want to avoid that. What about minimizing your app, prior to making word start/visible, have you tried that?
I also see that the Application object has a method Activate, but whether that will do, I have no idea.