megatronixs
Registered User.
- Local time
- Today, 21:19
- Joined
- Aug 17, 2012
- Messages
- 719
Hi all,
I managed to create some code today that will create a word document, add some text from and a table with text in it.
I can create the word doc with text, and I can create the word doc with the table. What I'm not able, is to combine them both so I will get the first part with text, then add the table with the text, add text below the table, and then add second table that will be more or less like the first table.
in the current version, it adds the text as it should, but then the table gets on top of the text and only the table will be visible.
Adding the second table is also impossible.
Below is the code I have so far:
Hope some one can help out
Greetings.
I managed to create some code today that will create a word document, add some text from and a table with text in it.
I can create the word doc with text, and I can create the word doc with the table. What I'm not able, is to combine them both so I will get the first part with text, then add the table with the text, add text below the table, and then add second table that will be more or less like the first table.
in the current version, it adds the text as it should, but then the table gets on top of the text and only the table will be visible.
Adding the second table is also impossible.
Below is the code I have so far:
Code:
Private Sub btn_create_word_check_list_Click()
Dim objWord As Word.Application
Dim doc As Word.Document
Dim WordHeaderFooter As HeaderFooter
Dim objDoc
Dim objRange
Dim objTable
Dim intNoOfRows
Dim intNoOfColumns
intNoOfRows = 5
intNoOfColumns = 6
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
With objWord
.Visible = True
Set doc = .Documents.Add
doc.SaveAs "C:\My DOcuments\Check List Docs\TestDoc.doc"
End With
With objWord.Selection
.Font.Name = "Calibri"
.Font.Size = 10
.TypeText "process check list"
.TypeParagraph
.TypeParagraph
.TypeText "BIN / Customer " & Me.BIN & " - " & Me.LE_Name
.TypeParagraph
.TypeParagraph
.TypeParagraph
.TypeText "Analyst Checklist"
.TypeParagraph
'Add header and footer
ActiveDocument.Sections(1).headers(wdHeaderFooterPrimary).Range.Text = "Header"
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = "Footer"
'====================================================
' Add the table after the above text
'====================================================
Set objRange = doc.Range
.Font.Name = "Calibri"
.Font.Size = 10
objRange.Tables.Add objRange, intNoOfRows, intNoOfColumns
Set objTable = doc.Tables(1)
objTable.Borders.Enable = True
'Column 1
objTable.Cell(1, 2).Range.Text = "1st year"
objTable.Cell(2, 1).Range.Text = "Date check complete"
objTable.Cell(2, 2).Range.Text = Date
objTable.Cell(3, 1).Range.Text = "SPI (Special Instructions)"
objTable.Cell(3, 2).Range.Text = GetUserName
objTable.Cell(4, 1).Range.Text = "NO Op's No Operations"
objTable.Cell(4, 2).Range.Text = GetUserName
objTable.Cell(5, 1).Range.Text = "Double Check"
objTable.Cell(5, 2).Range.Text = "(Insert Name)"
'Column 2
objTable.Cell(1, 3).Range.Text = "2nd year"
objTable.Cell(2, 3).Range.Text = "00/00/0000"
objTable.Cell(3, 3).Range.Text = "(Insert Name)"
objTable.Cell(4, 3).Range.Text = "(Insert Name)"
objTable.Cell(5, 3).Range.Text = "(Insert Name)"
'Column 3
objTable.Cell(1, 4).Range.Text = "3rd year"
objTable.Cell(2, 4).Range.Text = "00/00/0000"
objTable.Cell(3, 4).Range.Text = "(Insert Name)"
objTable.Cell(4, 4).Range.Text = "(Insert Name)"
objTable.Cell(5, 4).Range.Text = "(Insert Name)"
'Column 4
objTable.Cell(1, 5).Range.Text = "4th year"
objTable.Cell(2, 5).Range.Text = "00/00/0000"
objTable.Cell(3, 5).Range.Text = "(Insert Name)"
objTable.Cell(4, 5).Range.Text = "(Insert Name)"
objTable.Cell(5, 5).Range.Text = "(Insert Name)"
'Column 5
objTable.Cell(1, 6).Range.Text = "5th year"
objTable.Cell(2, 6).Range.Text = "00/00/0000"
objTable.Cell(3, 6).Range.Text = "(Insert Name)"
objTable.Cell(4, 6).Range.Text = "(Insert Name)"
objTable.Cell(5, 6).Range.Text = "(Insert Name)"
End With
'End With
'====================================================
' Add 1 line of text after the above table
'====================================================
.TypeText "Analyst Checklist"
'====================================================
' Add next table after the above Text with also 5 rows and 6 columns
'====================================================
doc.Save
doc.Activate
End Sub
Hope some one can help out

Greetings.