2017 Jul 05 6:50 PM
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
2017 Jul 06 2:48 AM
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).
2017 Jul 06 8:43 AM
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
2017 Jul 06 11:35 AM
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
2017 Jul 06 9:12 PM

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.
2017 Jul 06 9:16 PM
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.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |