Skip to Content
0

Word ole Question Problem

Jul 05, 2017 at 05:50 PM

91

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Sandra Rossi Jul 06, 2017 at 01:48 AM
0

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).

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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

0

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.

0
Former Member
  
  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

0
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.

uwebl.png (27.3 kB)
cj4oo.png (18.8 kB)
0