2010 Feb 28 2:14 PM
Hello gurus,
I need to merge two cells in the table created in MS Word by OLE automation.
The same code like the for Excel doesn't work and I can't find out how to get this working.
I can only select one cell at one point of time, but I can't select a range of cells to be merged together by next command.
Why this doesn't work?
Any suggestions?
Thanks
CALL METHOD OF w_table 'Cell' = w_selection1
EXPORTING
#1 = '5'
#2 = '1'.
CALL METHOD OF w_table 'Cell' = w_selection2
EXPORTING
#1 = '5'
#2 = '2'.
CALL METHOD OF w_table 'Range' = w_selection3
EXPORTING
#1 = w_selection1
#2 = w_selection2.
CALL METHOD OF w_selection3 'Select'.
CALL METHOD OF w_selection3 'Merge'.
2010 Feb 28 3:50 PM
Hi,
I think this may work in Excel, but in MS Word you need to do it in another way.
Try to record a macro in MS Word, and find out how MS Word handle it.
I've tried to record a macro when merging the two cells of a table in MS Word:
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Cells.Merge
That is we need to use selection object to do the cell merge, in MS Word .
Cheers,
2010 Feb 28 3:40 PM
your code seems really strange as Cell and Range are not methods, they just are properties. You should better search in Microsoft forums to get help.
2010 Feb 28 3:50 PM
Hi,
I think this may work in Excel, but in MS Word you need to do it in another way.
Try to record a macro in MS Word, and find out how MS Word handle it.
I've tried to record a macro when merging the two cells of a table in MS Word:
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Cells.Merge
That is we need to use selection object to do the cell merge, in MS Word .
Cheers,
2010 Feb 28 4:22 PM
Yes I've tried that before to record this macro, but what selection do I have to get...
There is no parametr "Selection" of the table so how can I select the two cells?
Thanks
2010 Mar 01 10:23 AM
You have to determine how to identify uniquely the table. For example, heading text. Then use selection.find to find and select this text. It will set selection property to the found text. Then use selection.rows or selection.cells, etc.
2010 Mar 06 11:58 AM
Thank you for your effort. Could you maybe pass here a code to do that...I'll try to figure out how it works out of it?
Thanks,
Petr
2010 Mar 06 1:36 PM
was pretty easy to record that as this is automatically done. In my case, the "left" cell contains "CELL CONTENT", and I want to merge it with the right cell :
Selection.Find.ClearFormatting
Selection.Find.Text = "CELL CONTENT"
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Cells.Merge
It's done
2010 Mar 06 1:39 PM
and to convert it into ABAP OLE statements, look at one of my answers in that thread
2010 Mar 06 2:36 PM
I've already seen many recordings...tried to convert them into ABAP statements, but nothing happend - probably I don't know how;( I can find/select the text in the cell but I can't select two cells together in order to merge them.
Do you actually know the ABAP coding to that? Can you please pass here the ABAP code, because it seems, that I'll not be able to figure out that from your hints;(
Or maybe it can be because of different SAPs/Words...I'm using 2007...I don't know.
thx,
petr
2010 Mar 06 3:30 PM
Translation of the above into ABAP OLE would be the following middle part, assuming that I use a Word document 'c:\test.docx' which already exists and contains the table where you want to merge the 2 cells:
TYPE-POOLS ole2.
DATA word_application TYPE ole2_object.
DATA documents TYPE ole2_object.
DATA document TYPE ole2_object.
CREATE OBJECT word_application 'word.application'.
GET PROPERTY OF word_application 'documents' = documents.
CALL METHOD OF documents 'Open' = document EXPORTING #1 = 'c:\test.docx'.
GET PROPERTY OF word_application 'selection' = selection.
Middle part:
DATA selection TYPE ole2_object.
DATA selection_find TYPE ole2_object.
DATA selection_cells TYPE ole2_object.
GET PROPERTY OF selection 'find' = selection_find.
CALL METHOD OF selection_find 'clearformatting'.
SET PROPERTY OF selection_find 'text' = 'CELL CONTENT'.
CALL METHOD OF selection_find 'execute'.
CALL METHOD OF selection 'MoveRight' EXPORTING #1 = 1 #2 = 2 #3 = 1.
GET PROPERTY OF selection 'cells' = selection_cells.
CALL METHOD OF selection_cells 'merge'.
End:
CALL METHOD OF document 'Save'.
CALL METHOD OF document 'Close'.
CALL METHOD OF word_application 'Quit'.
Edited by: Sandra Rossi on Mar 6, 2010 4:31 PM
Edited by: Sandra Rossi on Mar 6, 2010 4:38 PM
2010 Mar 06 3:52 PM
Thank you very much for your patience and help!!! Points awarded.
I didn't know what to give as a parameters for 'MoveRight' method.
Thanks a lot...really, you're OLE guru!
Petr