Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Word ole Question Problem

0 Likes
2,474

HI all,

Could you help me with solving a similar problem? I need to delete a row from a Table in WORD document.. I've recorded the macro in Word , but did not manage to translate it correctly to ABAP. What's wrong below? Please, help.

This is the macro VBA:

-----------------------------------------------------------------------

* sText = InputBox("Enter text for Row to be deleted")

Selection.Find.ClearFormatting

With Selection.Find

.Text = sText

.Wrap = wdFindContinue

End With

Do While Selection.Find.Execute

If Selection.Information(wdWithInTable) Then

Selection.Rows.Delete

End If

Loop

---------------------------------------------

This is my Abap Code .

data: clear type ole2_object.

data: word type ole2_object.

data: execute type ole2_object.

data: information type ole2_object.

data: row type ole2_object.

data: selection type ole2_object.

data: find type ole2_object, wdFindContinue type ole2_object,

delete TYPE ole2_object. .


CALL METHOD OF h_word 'ClearFormatting' = clear.

GET PROPERTY OF clear 'Selection' = selection.

GET PROPERTY OF selection 'find' = find.

SET PROPERTY OF find 'Text' = ' (D)'.

SET PROPERTY OF find 'Wrap' = wdFindContinue.

CALL METHOD OF find 'Execute' = execute.

GET PROPERTY OF selection 'Information' = information.

set PROPERTY OF selection 'Rows' = row.

CALL METHOD of row 'Delete' .

Thanks

HI all,

Could you help me with solving a similar problem? I need to delete a row from a Table in WORD document.. I've recorded the macro in Word , but did not manage to translate it correctly to ABAP. What's wrong below? Please, help.

This is the macro VBA:

-----------------------------------------------------------------------

* sText = InputBox("Enter text for Row to be deleted")

Selection.Find.ClearFormatting

With Selection.Find

.Text = sText

.Wrap = wdFindContinue

End With

Do While Selection.Find.Execute

If Selection.Information(wdWithInTable) Then

Selection.Rows.Delete

End If

Loop

---------------------------------------------

This is my Abap Code .

data: clear type ole2_object.

data: word type ole2_object.

data: execute type ole2_object.

data: information type ole2_object.

data: row type ole2_object.

data: selection type ole2_object.

data: find type ole2_object, wdFindContinue type ole2_object,

delete TYPE ole2_object. .


CALL METHOD OF h_word 'ClearFormatting' = clear.

GET PROPERTY OF clear 'Selection' = selection.

GET PROPERTY OF selection 'find' = find.

SET PROPERTY OF find 'Text' = ' (D)'.

SET PROPERTY OF find 'Wrap' = wdFindContinue.

CALL METHOD OF find 'Execute' = execute.

GET PROPERTY OF selection 'Information' = information.

set PROPERTY OF selection 'Rows' = row.

CALL METHOD of row 'Delete' .

Thanks

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
0 Likes
2,111

You must swap a few things in the first lines.

Assuming you have correctly created the object H_WORD, you must then do:

For selection.find.clearformatting :

GET PROPERTY OF h_word 'Selection' = selection.
GET PROPERTY OF selection 'find' = find. 
CALL METHOD OF find 'ClearFormatting'. 

Etc.

But why don't you go for abap2xlsx. It's more easy for a developer, much faster, and it works in background. But you can't create your code from the VBA, you must create the code from scratch (and eventually reuse a template workbook if you want).

Read only

0 Likes
2,111

Thanks Sandra for the answer.

The problem is that the format of the documents must be '.DOC' . i know that to use abap2xlsx is more simple but my template word can't be changed (it has been done ad HOC ).

I'll try to use your code and i'll know you .

Thanks

Read only

0 Likes
2,111

  
  GET PROPERTY OF h_word 'Selection' = selection.
  GET PROPERTY OF selection 'Find' = find.
  CALL METHOD OF find  'Text' " 'ClearFormatting'
      EXPORTING #01 = 'Mobility'
                #02 = 'wdFindContinue'.


  GET PROPERTY OF h_word 'Selection' = selection.
  GET PROPERTY OF selection 'Find' = find.
  CALL METHOD OF find 'Execute'.


*  GET PROPERTY OF h_word 'Selection' = selection.
*  CALL METHOD OF selection 'Information'
*        EXPORTING #01 = 'wdWithInTable'.


  GET PROPERTY OF h_word 'Selection' = selection.
  GET PROPERTY OF selection 'Rows' = row.
  CALL METHOD OF row 'Delete'.



Hi Sandra,

I have inserted this code in my Abap Report but it doesn't work:(

Where am I wrong ????

Thanks

Read only

0 Likes
2,111
I don't know where you have seen that "text" was a method of "find". Use the VBA Object Explorer (F2) to determine whether they are properties or methods:

So, "text" is a property, then you need to use SET PROPERTY OF find 'text' = 'Mobility' (mobility is the text you want Word to search).

You can't pass the constants wdFindContinue and other ones literally, you must pass their corresponding integer values. Use the VBA Object Explorer (F2) to display their real values. wdFindContinue value is 1, so you pass #2 = 1

But wdFindContinue is a constant for attribute Wrap, so you must use: SET PROPERTY OF find 'Wrap' = 1.

Be very rigorous when you convert manually VBA to ABAP, to keep the same coherence.

Read only

0 Likes
2,111

Ask the users if they can use the format .DOCX (the classic contraindication is that some of the target users have an old MS Word software version, which can't open .DOCX documents). If it's possible, they just have to save their template into .DOCX, nothing more.