1. william yau
  2. PowerBuilder
  3. Wednesday, 15 December 2021 09:14 AM UTC

hi guru

my application call word document format. code as below, One of  report failed to insertrow(1) , I traced the program trail and found

execute insertrow(1) in the loop. some is ok , some is failed, error messagebox as below. please advise

 

William

code :

 

 

 

 

Marco Meoni Accepted Answer Pending Moderation
  1. Wednesday, 15 December 2021 09:37 AM UTC
  2. PowerBuilder
  3. # 1

Hi William,

I am not an expert in Word oleobject, but looks like the syntax is wrong.

First of all, Microsoft doc

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

says "If the selection isn't in a table, an error occurs.". Your code doesn't seem to be aware whether you are in a Word table or not.

I imagine you must first check if you have a table with something like lo_mainp.ActiveDocument.Tables.Count (please refer to Word documentation), then select the table in question, and finally lo_mainp.ActiveDocument.Selection.InsertRows( 1).

Btw, whenever I am unsure about Excel/Word oleobject syntax, I register a Macro and then "copy&paste" the syntax to PowerBuilder 

https://support.microsoft.com/en-us/office/create-or-run-a-macro-c6b99036-905c-49a6-818a-dfb98b7c3c9c

Lazy approach but saves me from syntax headache.
Hope that helps.

Best,

.m

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.