Hi,
Below is an exert of a code that transfers data from Excel to word via a series of .bookmarks. The macro opens a word template (.docx), populates certain bookmarks and saves in a defined directory.
Everything is working fine, with exception, I cannot get the word window to open. When users are using the spreadsheet, they assume the macro has not worked as Word does not appear on their desktop. Is there a way to make word do this, so when user runs the code, word appears over the top of excel on their monitor.
Thanks
Below is an exert of a code that transfers data from Excel to word via a series of .bookmarks. The macro opens a word template (.docx), populates certain bookmarks and saves in a defined directory.
Everything is working fine, with exception, I cannot get the word window to open. When users are using the spreadsheet, they assume the macro has not worked as Word does not appear on their desktop. Is there a way to make word do this, so when user runs the code, word appears over the top of excel on their monitor.
Thanks
Code:
'F) Activate word
Set objWord = CreateObject("Word.Application")
Set objdoc = objWord.documents.Add
objWord.Visible = True
objWord.documents.Open Filename:=fpathtemplate & "\" & fnametemplate
With objWord.activedocument
.bookmarks("Date").Range.Text = wsRegister.Cells(btmrow, 11).Text
.bookmarks("ReportNumber").Range.Text = wsRegister.Cells(btmrow, 10).Text
.bookmarks("EquipmentNumber").Range.Text = wsRegister.Cells(btmrow, 7).Text
.bookmarks("Heading_2").Range.Text = wsRegister.Cells(btmrow, 7).Text
.bookmarks("Unit").Range.Text = wsRegister.Cells(btmrow, 6).Text
.bookmarks("Area").Range.Text = wsRegister.Cells(btmrow, 5).Text
.bookmarks("WorkOrder").Range.Text = wsRegister.Cells(btmrow, 3).Text
.bookmarks("Person").Range.Text = wsRegister.Cells(btmrow, 12).Text
Select Case wsRegister.Cells(btmrow, 9).Text
Case Is = "INT": .bookmarks("Heading_1").Range.Text = "Internal"
Case Is = "EXT": .bookmarks("Heading_1").Range.Text = "External"
End Select
.bookmarks("Extent").Range.Text = wsRegister.Cells(btmrow, 9).Text
.bookmarks("HazardLevel").Range.Text = Application.VLookup(wsRegister.Cells(btmrow, 7), Range("tableEQUIPMENTNUMBER"), 8, False)
End With
'G) Save document
objWord.activedocument.SaveAs Filename:=Fpath & "\" & FVariable & "\" & Fname
Set objWord = Nothing
End Select