1. Pierre Couvreur
  2. PowerBuilder
  3. Thursday, 9 September 2021 14:30 PM UTC

Hello,

After a mailmerge with a document containing INCLUDEPICTURE fields, it is necessary to refresh the document by pressing F9 in Word.

To avoid that, I coded "lole_doc.Fields.Update" after the mailmerge.execute in my Powerscript mailmerge function. It works BUT only on the first story.

To make the update on each story, I would like to mimic that VBA macro in Powerscript :

Sub UpdateAllFieldsInDocument()
Dim rngStory As Range
'Iterate through all stories and update fields
For Each rngStory In ActiveDocument.StoryRanges
   If Not rngStory Is Nothing Then
     'Update fields directly in story
      rngStory.Fields.Update
   End If
Next rngStory
End Sub

Unfortunately I don't know how to replic that loop on each story.

Does someone know that ?

Thank you very much by advance !

Pierre.

Pierre Couvreur Accepted Answer Pending Moderation
  1. Monday, 13 September 2021 07:34 AM UTC
  2. PowerBuilder
  3. # 1

Hi Miguel and John,

Thank you very much for having take time to answer me.

Miguel, I indeed tried your suggestion but the security prompts are really a "no go" in my organization. Moreover, I fear that some proxy or firewall would block my attempts to deploy a Word document with a macro.

I found on the web that by surrounding the merge field (containing the path to the picture) with {IF TRUE }, the update would be automatic. The field becomes like that : {INCLUDEPICTURE "{IF TRUE {MERGEFIELD picture_path}}"} .

Believe it or not but it seems to works ! I'll give it a try in my organization because it seems too simple to be true, and if it is not reliable I will try to follow John's approach. 

Thank you and Best regards,

Pierre

 

 

Comment
  1. Miguel Leeuwe
  2. Monday, 13 September 2021 14:39 PM UTC
yes, I was afraid of the security problem. Glad you worked it out though and thanks for sharing !
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 10 September 2021 20:09 PM UTC
  2. PowerBuilder
  3. # 2

In addiction to what John said:

The VBA macro code looks a bit difficult (to me), to simply replicate with OLE in powerbuilder as I don't know about a lot of the types, but it should be possible.
Maybe an easier way to do this, would be to create your document using a DOTX (or DocM?) file which already contains that macro. (I think you can also add a macro dynamically to any other document, but it's been a very long time since I've done that).

Once that's done, you'd only have to run that macro using OLE from powerbuilder.

A disadvantage of using a predifined macro might be running into more security prompts when opening the docs etc.

Just an idea.

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 10 September 2021 19:36 PM UTC
  2. PowerBuilder
  3. # 3

Hi, Pierre -

Disclaimer: I've never done this, but here's how I would approach the problem:

You'll need Word Object Model documentation:

https://docs.microsoft.com/en-us/office/vba/api/overview/Word/object-model

The StoryRanges object is a collection, according to the documentation. So lookup the StoryRanges object:

https://docs.microsoft.com/en-us/office/vba/api/word.storyranges

You'll see a list of Properties and a list of Methods for the StoryRanges object. Collections always (in my limited experience) have a Count property that tells you the number of items in the collection. You can use this in a PB For-Next loop.

There is an Item method you use to obtain a desired item number from the collection. If you drill down into this method, you'll see it returns a Range object and the web page shows you the syntax. You'll assign this to another PB OLEObject.

Now look up the Range object:

https://docs.microsoft.com/en-us/office/vba/api/word.range

There appears to be roughly a gazillion methods and properties for the Range object, so I have no idea where you go from here, but I hope you get the idea on how to attack the problem.

Good luck and best regards, John

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.