Andreas Hermle
asked on
Convert text to table using VBA
Dear Experts:
I got two questions:
QUESTION 1:
I would like to convert text to a table. The text to be converted ...
... starts from paragraph 2 and ends at the very end of the document.
... The separator is to be 'COMMAS'.
I am using below code. It works fine but I'd rather use a range object instead of the selection object.
QUESTION 2:
The macro "InsertOneRowAboveTheFirst One" inserts a row above the first one. I would like to enter text in each cell of the newly created table row. How is this achieved using VBA?
Help is much appreciated. Thank you very much in advance.
I have attached a sample file for your convenience.
Regards, Andreas SAMPLE-FILE-TABLE-MACRO.docx
I got two questions:
QUESTION 1:
I would like to convert text to a table. The text to be converted ...
... starts from paragraph 2 and ends at the very end of the document.
... The separator is to be 'COMMAS'.
I am using below code. It works fine but I'd rather use a range object instead of the selection object.
QUESTION 2:
The macro "InsertOneRowAboveTheFirst
Help is much appreciated. Thank you very much in advance.
I have attached a sample file for your convenience.
Regards, Andreas SAMPLE-FILE-TABLE-MACRO.docx
Sub ConvertToTableSeparatedByCommas
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdParagraph
Selection.EndKey Unit:=wdStory, Extend:=wdExtend
WordBasic.TextToTable NumColumns:=3
End Sub
Sub InsertOneRowAboveTheFirstOne
Dim tbl as table
Dim rng as range
Dim rows as rows
Set tbl = ActiveDocument.Tables(1)
Set rng = tbl.rows(1).Range
Set rows = rng.rows
rows.Select
Selection.InsertRowsAbove 1
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear Graham,
thank you very much for your swift support. Q1 is fully answered. Thank you very much.
As for Q2, I guess, I should have been more precise. The text in the newly created cells in row 1 should be different in all the three cells, i.e.
Cell 1 of first row: Page
Cell 2 of first row: Code
Cell 3 of first row: Submitted
Thank you very much in advance for your great help.
Regards, Andreas
thank you very much for your swift support. Q1 is fully answered. Thank you very much.
As for Q2, I guess, I should have been more precise. The text in the newly created cells in row 1 should be different in all the three cells, i.e.
Cell 1 of first row: Page
Cell 2 of first row: Code
Cell 3 of first row: Submitted
Thank you very much in advance for your great help.
Regards, Andreas
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Graham,
great, that's it. Thank you very much for your great support. Regards, Andreas
great, that's it. Thank you very much for your great support. Regards, Andreas
Open in new window