Write in Word document using automation

ServalServal Member Posts: 51
Hi people !

I'm using Word automations. I have to write some informations from Navision to a Word template wich is stored as a blob in the Interaction Template table. There are already some fields created in the Word template wich is structured as header and a footer.

How can I perform the following actions :

1. write a value from Navision to a field in the Word Document.

2. write additional texts between the header and the footer. This means that I have to know where the header ends and where the bottom starts in order to prevent replacing my existing fields.


What are the properties and/or methods to use ?

Any samples in VB are welcome.

NB : I have already search the forum. I found some topics those have already help me to perfom a lot of others actions, but I still need to know how to do for the 2 above and time is money ...

Thx in advance.

Comments

  • nunomaianunomaia Member Posts: 1,153
    In Microsoft Word

    Tools -> Macros -> Record a new Macro.

    Manually make all changes you want to do.
    Stop Recording.

    Check Macro Source Code. You will there the code in VBA that you convert to C/AL.
    Nuno Maia

    Freelance Dynamics AX
    Blog : http://axnmaia.wordpress.com/
  • ServalServal Member Posts: 51
    Thanks nunomaia, the Macro recording function is really helpful.

    But I still face the first problem. How to write into a MergeField in a Word document from Navision using automation... ??
    ](*,)
    Thanks.
  • ufukufuk Member Posts: 514
    Have you checked ExecuteMerge function in WordManagement codeunit?
    Ufuk Asci
    Pargesoft
  • ServalServal Member Posts: 51
    ufuk wrote:
    Have you checked ExecuteMerge function in WordManagement codeunit?
    I have already check this function. I tried to use the AddField function, but no way, it doesn't work.
    Is the 'Navision Attain ApplicationHandler'.MergeHandler' automation specific to the Service module and functionalities....? :-k

    Anyway, I found another solution, this may not be the perfect solution, but it works :
    -I declare a new automation variable (autWrdAp) of Subtype 'Microsoft Word 11.0 Object Library'.Document.
    -To find a text and replace it by another text in a word template, I use the Execute method :
    autWrdDoc.Content.Find.Execute(FindText,[some others parameters],ReplaceText)
  • DatapacDatapac Member Posts: 97
    I was wondering what are the other parameters required for autWrdDoc.Content.Find.Execute(FindText,[some others parameters],ReplaceText)
    [/quote]
  • ArhontisArhontis Member Posts: 667
    I had some problems regarding replace, but I managed to overcome them by doing:
    pWordAF.ActiveWindow.Selection.SetRange(0,0);//select nothing
    IF pWordAF.ActiveWindow.Selection.Find.Execute(temptext) THEN//find and select
      pWordAF.ActiveWindow.Selection.TypeText:=pReplaceText;//the actual replace
    
  • DatapacDatapac Member Posts: 97
    Thanks Arhontis, that has solved my problem
  • ServalServal Member Posts: 51
    Datapac wrote:
    I was wondering what are the other parameters required for autWrdDoc.Content.Find.Execute(FindText,[some others parameters],ReplaceText)
    [some others parameters] = 8 others parameters (7 booleans + 1 integer).

    If those parameters do not need to be changed, just declare two variables :
    bParam : boolean
    iParam : integer
    then run the function as follow :

    autWrdDoc.Content.Find.Execute(FindText,,bParam,bParam,bParam,bParam,bParam,bParam,iParam,bParam,ReplaceText);

    For more informations about these others parameters, use the Record Macro functionality in Microsoft Word as explain by Nunomaia above. :wink:
  • BT_MarcBT_Marc Member Posts: 30
    So I never made an Report form Navision in to Word. Can somebody send me an complete Report so I can see the automations witch are needed to write in an Word Template.
  • ajhvdbajhvdb Member Posts: 672
    I created a lot of exports to msWord and learned it by using the search button in this forum. Here is a link i started with http://www.mibuso.com/forum/viewtopic.p ... automation
Sign In or Register to comment.