nardagus
Active Member
- Joined
- Apr 23, 2012
- Messages
- 317
- Office Version
- 2016
- 2013
- Platform
- Windows
Hello,
Heh. It is time for me to ask a question.
I have an excel file with a data I need to transfer to a new word document using macro.
I did almost everything I needed except one thing. But first things first.
Structure of a word document is so far as follows:
--------------------------
Some text (generated by excel)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]col1[/TD]
[TD]col2[/TD]
[TD]col3[/TD]
[/TR]
[TR]
[TD]some data[/TD]
[TD]some data[/TD]
[TD]some data[/TD]
[/TR]
[TR]
[TD]some data[/TD]
[TD]some data[/TD]
[TD]some data[/TD]
[/TR]
</tbody>[/TABLE]
(table is also generated and filled by excel)
---------------------------
What I'm struggling with is how to insert a form field after a table (wdContentControlRichText) ?
I have no problem inserting it in a document but it is inserted in the most left upper cell of a table. Question is why in a table and not at the very beginning of a document?
Here is a part of a macro. It only inserts
I tried to use this piece:
but it didn't work. I read somewhere that it requires excel to be visible but since I need to generate around 30 documents from this excel I want to save a user a "pleasure" to watch it generated.
Is there a way to tell excel the place field should be insterted in or maybe I can jump to the end of the document (ctrl-END) without making excel visible?
I hope I explained my issue clearily.
Thank you for help.
Heh. It is time for me to ask a question.

I have an excel file with a data I need to transfer to a new word document using macro.
I did almost everything I needed except one thing. But first things first.
Structure of a word document is so far as follows:
--------------------------
Some text (generated by excel)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]col1[/TD]
[TD]col2[/TD]
[TD]col3[/TD]
[/TR]
[TR]
[TD]some data[/TD]
[TD]some data[/TD]
[TD]some data[/TD]
[/TR]
[TR]
[TD]some data[/TD]
[TD]some data[/TD]
[TD]some data[/TD]
[/TR]
</tbody>[/TABLE]
(table is also generated and filled by excel)
---------------------------
What I'm struggling with is how to insert a form field after a table (wdContentControlRichText) ?
I have no problem inserting it in a document but it is inserted in the most left upper cell of a table. Question is why in a table and not at the very beginning of a document?
Here is a part of a macro. It only inserts
Code:
sub addform()
Dim objWord
Dim objDoc As Object
Dim objSelection As Object
On Error Resume Next
'checking if word is opened
Set objWord = GetObject(, "Word.Application")
'if not we open it
If objWord Is Nothing Then
Set objWord = CreateObject("Word.Application")
End If
'creating a new document
Set objDoc = objWord.Documents.Add
'making word invisible
objWord.Visible = False
'some selection variable, lazy ppl rule
Set objSelection = objWord.Selection
' inserting some text
objSelection.Font.Name = "Calibri"
objSelection.Font.Size = "14"
objSelection.Font.Color = RGB(146, 208, 80)
objSelection.TypeText "Client:"
'insert a table
objSelection.Tables.Add Range:=objSelection.Range, NumRows:=21, NumColumns:= _
9, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
'trying to insert
objSelection.Range.ContentControls.Add (wdContentControlRichText)
end sub
I tried to use this piece:
Code:
objSelection.EndKey Unit:=wdStory
but it didn't work. I read somewhere that it requires excel to be visible but since I need to generate around 30 documents from this excel I want to save a user a "pleasure" to watch it generated.
Is there a way to tell excel the place field should be insterted in or maybe I can jump to the end of the document (ctrl-END) without making excel visible?
I hope I explained my issue clearily.
Thank you for help.