Hi guys,
I hope this is the right forum for this question. I'm fairly competent in VBA in Excel, but recently started tinkering with creating letters in MS Word from our Excel VBA programmed management system. I work in Microsoft 365.
I'm creating a Word document from scratch (out of Excel), and start putting together the letter with some client info. After that I need to put in a table with three columns and ten rows. The first row should have text that act as headers - "Name", "ID nr" and "Signature". The columns should have about the spacing of letter size 18.
I've been playing around with code for a few days and have tried multiple searches on forums. For some reason I just cannot get it right. Here's part of my code for creating the Word file and getting the letter started:
Any assistance with inserting the table correctly will be greatly appreciated.
Regards
dwsteyl
I hope this is the right forum for this question. I'm fairly competent in VBA in Excel, but recently started tinkering with creating letters in MS Word from our Excel VBA programmed management system. I work in Microsoft 365.
I'm creating a Word document from scratch (out of Excel), and start putting together the letter with some client info. After that I need to put in a table with three columns and ten rows. The first row should have text that act as headers - "Name", "ID nr" and "Signature". The columns should have about the spacing of letter size 18.
I've been playing around with code for a few days and have tried multiple searches on forums. For some reason I just cannot get it right. Here's part of my code for creating the Word file and getting the letter started:
VBA Code:
Dim wdApp As Word.Application
Dim objSelection
Set wdApp = New Word.Application
With wdApp
.visible = True
.Activate
.Documents.Add
.Selection.WholeStory 'select all informaiton
.Selection.Style = ("No Spacing") 'change style
Set objSelection = wdApp.Selection
Dim ClientLongName As String
ClientLongName = UCase(txtRegSurname.Text)
objSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter
objSelection.Font.Underline = wdUnderlineSingle
objSelection.Font.Bold = True
objSelection.Font.Size = 18
objSelection.TypeText ClientLongName
objSelection.TypeParagraph
objSelection.TypeParagraph
objSelection.ParagraphFormat.Alignment = wdAlignParagraphCenter
objSelection.Font.Underline = wdUnderlineNone
objSelection.Font.Bold = True
objSelection.Font.Size = 12
objSelection.TypeText "RE: MANDATE FOR UPLOADING BENEFICIAL OWNERSHIP WITH THE COMPANIES AND INTELLECTUAL PROPERTY COMMISSION (CIPC)"
objSelection.TypeParagraph
objSelection.TypeParagraph
objSelection.ParagraphFormat.Alignment = wdAlignParagraphJustify
objSelection.Font.Underline = wdUnderlineSingle
objSelection.Font.Bold = False
objSelection.TypeText "Introduction: "
objSelection.TypeParagraph
objSelection.TypeText "Beneficial Ownership: Preparation and lodgement of documents to CIPC."
objSelection.TypeParagraph
'I need to enter a table here with 3 columns and 10 rows. The first row should act as headers with the headings "Name", "ID nr" and "Signature"
End With
Any assistance with inserting the table correctly will be greatly appreciated.
Regards
dwsteyl