I have been trying to find a solution to my roblem, BUT can not find it anywhere.
Simply put, I have data (a list) I want to put into a word document. However whenever my text is inserted to the bookmark the Word style automatically reverts the the "normal" style and not to the style I save the bookmark in.
I'm sure it's just a simple thing of selecting the style I want before I insert the text... but I'm going mad trying to find it.
This is my code:
Simply put, I have data (a list) I want to put into a word document. However whenever my text is inserted to the bookmark the Word style automatically reverts the the "normal" style and not to the style I save the bookmark in.
I'm sure it's just a simple thing of selecting the style I want before I insert the text... but I'm going mad trying to find it.
This is my code:
Sub test1()
Dim objWord As Object
Dim ws As Worksheet
Dim ScopeItem, Amendments, SOWDate As String
Dim i, n As Long
'Dim SOWDate As Date
Set ws = ThisWorkbook.Sheets("02050")
Set objWord = CreateObject("Word.Application")
i = ws.Range("B" & Rows.Count).End(xlUp).Row
SOWDate = Format(Now, "MMM dd, YYYY")
ScopeItem = Chr(149) & " All scope items as per drawings and specifications, including" & ws.Range("B3").Value & Chr(13)
For n = 9 To i
ScopeItem = ScopeItem & Chr(149) & " " & ws.Range("B" & n).Value & Chr(13)
Next n
objWord.Visible = True
'objWord.Documents.Open "C:\Users\Josh\OneDrive\SOW Manager\Scope of Work Template V1.0 TEST.dotx" ' change as required
objWord.Documents.Open "C:\Users\Eustung\OneDrive\SOW Manager\SOW Template V1.0.dotm" ' change as required
With objWord.ActiveDocument
.Bookmarks("Scope").Range.Text = ScopeItem 'But not in "normal" style! In my "List" style
.Bookmarks("ProjectName").Range.Text = ws.Range("B1").Value
.Bookmarks("ProjectNumber").Range.Text = ws.Range("B2").Value
.Bookmarks("TradeName").Range.Text = ws.Range("B6").Value
.Bookmarks("CostCode").Range.Text = ws.Range("B4").Value
.Bookmarks("DivisionNameHeader").Range.Text = ws.Range("B5").Value
.Bookmarks("DivisionName").Range.Text = ws.Range("B5").Value
.Bookmarks("SOWDate").Range.Text = SOWDate
End With
Set objWord = Nothing
End Sub