Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Button_Click()
- Dim objWord
- Dim objDoc
- Dim objRange
- Dim objTable
- Dim ws As Worksheet
- Set ws1 = ThisWorkbook.Sheets("Vessel Details")
- Set ws2 = ThisWorkbook.Sheets("Risk Assessment")
- 'Create the object of Microsoft Word
- Set objWord = CreateObject("Word.Application")
- '----------
- Set objDoc = objWord.Documents.Add
- Set objRange = objDoc.Range
- objDoc.Tables.Add objRange, 13, 1, wdWord9TableBehavior
- Set objTable = objDoc.Tables(1)
- objTable.Borders.Enable = True
- objTable.Columns.AutoFit
- '----------
- 'Adds logo from file location specified
- With objTable.Cell(1, 1)
- .Range.InlineShapes.AddPicture "C:File_LocationLogo.png"
- End With
- '----------
- With objTable.Cell(2, 1)
- 'Shades the cell
- .Shading.BackgroundPatternColor = RGB(217, 217, 217)
- With .Range
- 'Centres the text
- .ParagraphFormat.Alignment = 1
- .Font.Size = 16
- .Font.Bold = True
- .Text = "Risk Assessment of Pressure Vessel"
- End With
- End With
- '----------
- With objTable.Cell(3, 1)
- With .Range
- .Font.Bold = True
- End With
- .Range.Text = "Please note that a statutory inspection of this vessel has previously been carried out by Metlab and that the recommendations of this assessment do not alter any of the recommendations set forth in those inspections. "
- End With
- '----------
- objTable.Cell(4, 1).Split 2, 4
- '----------
- With objTable.Cell(4, 1).Range
- .Font.Bold = True
- .Paragraphs.SpaceAfter = 0
- .Text = "Project No.:"
- End With
- '----------
- objTable.Cell(4, 2).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(4, 2).Range.Text = ws1.Range("D3").Value
- '----------
- With objTable.Cell(4, 3).Range
- .Font.Bold = True
- .Paragraphs.SpaceAfter = 0
- .Text = "Date:"
- End With
- '----------
- objTable.Cell(4, 4).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(4, 4).Range.Text = ws1.Range("G3").Value
- '----------
- With objTable.Cell(5, 1).Range
- .Font.Bold = True
- .Paragraphs.SpaceAfter = 0
- .Text = "Examination carried out by:"
- End With
- '----------
- objTable.Cell(5, 2).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(5, 2).Range.Text = ws1.Range("D5").Value
- '----------
- With objTable.Cell(6, 1)
- .Shading.BackgroundPatternColor = RGB(217, 217, 217)
- With .Range
- .ParagraphFormat.Alignment = 1
- .Font.Size = 14
- .Font.Bold = True
- .Text = "Vessel Details"
- End With
- End With
- '----------
- objTable.Cell(7, 1).Split 6, 4
- '----------
- objTable.Cell(7, 1).Range.Font.Bold = True
- objTable.Cell(7, 1).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(7, 1).Range.Text = "Irish Water Region:"
- '----------
- objTable.Cell(7, 2).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(7, 2).Range.Text = ws1.Range("D9").Value
- '----------
- objTable.Cell(7, 3).Range.Font.Bold = True
- objTable.Cell(7, 3).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(7, 3).Range.Text = "Local Authority:"
- '----------
- objTable.Cell(7, 4).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(7, 4).Range.Text = ws1.Range("G9").Value
- '----------
- objTable.Cell(8, 1).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(8, 1).Range.Font.Bold = True
- objTable.Cell(8, 1).Range.Text = "Site Location:"
- '----------
- objTable.Cell(8, 2).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(8, 2).Range.Text = ws1.Range("D11").Value
- '----------
- objTable.Cell(8, 3).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(8, 3).Range.Font.Bold = True
- objTable.Cell(8, 3).Range.Text = "Site Address:"
- '----------
- objTable.Cell(8, 4).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(8, 4).Range.Text = ws1.Range("G11").Value
- '----------
- objTable.Cell(9, 1).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(9, 1).Range.Font.Bold = True
- objTable.Cell(9, 1).Range.Text = "Plant Description:"
- '----------
- objTable.Cell(9, 2).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(9, 2).Range.Text = ws1.Range("D13").Value
- '----------
- objTable.Cell(9, 3).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(9, 3).Range.Font.Bold = True
- objTable.Cell(9, 3).Range.Text = "Asset Type:"
- '----------
- objTable.Cell(9, 4).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(9, 4).Range.Text = ws1.Range("G13").Value
- '----------
- objTable.Cell(10, 1).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(10, 1).Range.Font.Bold = True
- objTable.Cell(10, 1).Range.Text = "Equipment Category:"
- '----------
- objTable.Cell(10, 2).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(10, 2).Range.Text = ws1.Range("D15").Value
- '----------
- objTable.Cell(10, 3).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(10, 3).Range.Font.Bold = True
- objTable.Cell(10, 3).Range.Text = "Serial Number"
- '----------
- objTable.Cell(10, 4).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(10, 4).Range.Text = ws1.Range("G15").Value
- '----------
- objTable.Cell(11, 1).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(11, 1).Range.Font.Bold = True
- objTable.Cell(11, 1).Range.Text = "Metlab Report No.:"
- '----------
- objTable.Cell(11, 2).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(11, 2).Range.Text = ws1.Range("D17").Value
- '----------
- objTable.Cell(11, 3).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(11, 3).Range.Font.Bold = True
- objTable.Cell(11, 3).Range.Text = "Easting/Northing:"
- '----------
- objTable.Cell(11, 4).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(11, 4).Range.Text = ws1.Range("G17").Value
- '----------
- objTable.Cell(12, 1).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(12, 1).Range.Font.Bold = True
- objTable.Cell(12, 1).Range.Text = "MX Number:"
- '----------
- objTable.Cell(12, 2).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(12, 2).Range.Text = ws1.Range("D19").Value
- '----------
- objTable.Cell(12, 3).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(12, 3).Range.Font.Bold = True
- objTable.Cell(12, 3).Range.Text = "Facility ID:"
- '----------
- objTable.Cell(12, 4).Range.Paragraphs.SpaceAfter = 0
- objTable.Cell(12, 4).Range.Text = ws1.Range("G19").Value
- '----------
- 'Table 1 continues below, but code is the very same as above
- '----------
- '----------
- 'End of Table 1
- '----------
- '----------
- '----------
- 'Adding Second Table
- '----------
- '----------
- Set objRange = objDoc.Range
- objDoc.Tables.Add objRange, 8, 1, wdWord9TableBehavior
- Set objTable = objDoc.Tables(1)
- objTable.Borders.Enable = True
- objTable.Columns.AutoFit
- '----------
- With objTable.Cell(1, 1)
- With .Range
- .Paragraphs.SpaceAfter = 0
- .Font.Bold = True
- .Font.Underline = xlUnderlineStyleSingle
- .Text = "Exclusion Zones"
- End With
- End With
- '----------
- 'Table 2 continues below, formatting of table same as table 1
- '----------
- 'Make the MS Word Visible
- With objWord
- .Visible = True
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement