1. David Vasconcelos
  2. PowerBuilder
  3. Thursday, 20 May 2021 17:49 PM UTC

I am trying to highlight a bookmark, following code gives me an error. Anyone have any ideas on how to do this?

iole_word.ActiveDocument.Bookmarks.Item(avs_bookmark).Range.HighlightColorIndex = ll_hcolor

I struggle with OLE is there any document or directions on how to convert/interpret the Microsoft VBA (Object Model code) to PB?

 

ll_hcolor = 7 which is Yellow

Thanks in advance

Dave V.

 

Environment...

PB2017r3, Office Pro

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Friday, 21 May 2021 05:58 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi David,

Catch the OLERuntimeError exception for your statement and see the Word error message in the description property of the exception to get more information.

To see what part of the statement is the problem you can separate it, e.g.:

oleobject lole_bookmark

try

lole_bookmark = iole_word.ActiveDocument.Bookmarks.Item(avs_bookmark)

lole_bookmark.Range.HighlightColorIndex = ll_hcolor

catch (oleruntimeerror e)

Messagebox ("oleruntimeerror", e.description)

end try

 

Often you can use VBA code with only litte changes in PowerBuilder. I don't know a way how to use the enumerated values like wdYellow (of WdColorIndex) so I have hard coded it. And you have to replace code to acces items like Bookmarks("test") to Bookmarks.Item("test").

HTH,

René

 

Comment
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Thursday, 20 May 2021 19:56 PM UTC
  2. PowerBuilder
  3. # 1


Hi Dave,

What is the error you're receiving? Did you try hardcoding a value in for avs_bookmark to see if the value is the problem? Have you placed a value into the bookmark before or after trying to highlight the bookmark? If you placed a value into the bookmark before trying to highlight it I suspect the bookmark is no longer there...what is the line of code you use to place a value into the bookmark?

Regards,

Mark

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 21 May 2021 02:45 AM UTC
  2. PowerBuilder
  3. # 2

Hi, David - 

In regards to your question regarding documentation or directions on how convert/interpret the Office VBA Object Model to PowerScript, there isn't any that I'm aware of. I know firsthand how difficult this can be.

When you're stymied on how to accomplish a task like this one, I suggest you first search the Microsoft Office forums for a VBA solution. If you can find an answer that is coded in VBA, then ask your question here and include the VBA code so we can all see the VBA solution and help you translate it into PB OleObject calls.

 Best regards, John

Comment
There are no comments made yet.
David Vasconcelos Accepted Answer Pending Moderation
  1. Friday, 21 May 2021 11:39 AM UTC
  2. PowerBuilder
  3. # 3

Thanks everyone... turns out the field is locked/protected and due to that highlight cannot be performed hence the error.  Thanks Rene, the ole return error gave me more info that led me to the issue.

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.