Navision and Word

MurielleMMurielleM Member Posts: 3
edited 2000-07-28 in Navision Financials
Hello,

I took the program "NF automation Examples" to do my first program with Word.
It doens't works ! I receive this message "Impossible to activate this application".
Do you know what it's wrong ?

wdApp : Microsoft Word 9.0 Object Library - Application
wdDoc : Microsoft Word 9.0 Object Library - Document
wdRange : Microsoft Word 9.0 Object Library - Range

CLEARALL;
CREATE(wdApp);
wdApp.Activate();
TemplateName := 'C:\WINDOWS\Application Data\Microsoft\Modèles\My Documents\Normal.dot';
wdDoc := wdApp.Documents.AddOld(TemplateName);
wdApp.ActiveDocument.Fields.Update;
wdRange := wdApp.ActiveDocument.Fields.Item(1).Result;
wdRange.Text := 'Coucou, je suis ici !!!';
wdRange.Bold := 0;
wdApp.Visible := TRUE;
wdApp.ActiveDocument.Fields.Unlink;

Thank you for your help,

Regards,

Murielle.

Murielle M
Murielle M

Comments

  • mfabianmfabian Member Posts: 187
    Hi Muriel,

    There are two mistakes in your code:

    1) 3rd line: wdApp.Activate();
    Delete this statement. There is nothing to activate at this very moment! The active application at this point is Navision, not WinWord.

    2) 4th line: TemplateName := '...\Normal.dot';
    Wrong template: Normal.dot does only contain styles but is not a document. If you take the original example you will see that the example refers to "real" documents. So I suggest you do the following: Manually create a new document (based on Normal.DOT if you like), insert some Text and some fields, save it under a template name (e.g. C:\Temp\MaLettre.DOT) and use this DOT-file as template.

    3) line 2: CREATE(wdApp)
    This is not wrong but you can do better by adding the ",False" parameter to the CREATE statement. In case WinWord is already started, the False Parameter will use the existing instance of Winword rather than creating a new instance. Thus use something like:

    IF NOT CREATE(wdApp,FALSE) THEN
    ERROR('Could not start WinWord as Automation server\'+
    'Coucou, je ne suis pas capable d''executer!');

    Hope this works

    salutations

    Marcus

    ---
    Note to all automation programmers
    If you have an error in an automation sequence (to be specific between Application.Create and Application.Visible) your office application (WinWord, Excel ...) will be instantiated but not be visible: You will have the application started but you don't see anything in the task bar. The only chance to deactivate the application is to press Ctrl-alt-del and shut down the open task. According to my experience this will help sometimes, sometimes your whole windows will crash! So make sure you have no important files open while playing with office-automation!

    During programming/testing, I recommend to have the application always visible (--> put the line wdApp.Visible := TRUE; after the CREATE statement) This will considerably slow down the execution (especially in large Excel sheets) but it helps you to keep track of "what's going on" and how far your routine works properly. After all tests have passed successfully, you might move the "Visible := TRUE" again to the end of the procedure.



    Marcus Fabian
    m.fabian@thenet.ch
    +41 79 439 78 72
    With best regards from Switzerland

    Marcus Fabian
  • MurielleMMurielleM Member Posts: 3
    Hi,

    It's still me. I have corrected this program.
    And I have again a problem.
    I define some automation :
    wdDoc (Document)
    wdRange(Range)
    wdApp(Application)

    And I receive this message :
    Sorry it's in french : "Le membre de la collection requis n'existe pas". ("The collection member doesn't exist").
    The problem is with the ITEM(11).


    CLEARALL;
    IF NOT CREATE(wdApp,FALSE) THEN
    ERROR('probleme d''ouverture');
    wdDoc := wdApp.Documents.Add();
    wdApp.ActiveDocument.Fields.Update;
    wdRange := wdApp.ActiveDocument.Fields.Item(11).Result;
    wdRange.Text := 'coucou';
    wdRange.Bold := 0;
    wdApp.Visible := TRUE;
    wdApp.ActiveDocument.Fields.Unlink;

    Thank you for your help,

    Best Regards,

    Murielle.
    Murielle M
  • mfabianmfabian Member Posts: 187
    Well, you are trying to access Field No 11, which simply doesn't exist. How many fields are defined?
    With best regards from Switzerland

    Marcus Fabian
Sign In or Register to comment.