Hi,
I am trying to insert excel data into a word document. Below is my code to show how I am trying to do it:
Code:
Private Sub chkboxTest_Click()
Dim oXA As Word.Application
Dim oXB As Word.Document
Dim rngExcelTest As Word.Range
Dim strAddCheck As String
Set oXA = Word.Application
If strAddCheck = "added" Then
Set oXB = oXA.Documents.Open("H:\proposalDocumentDevelopment\HVAC\experiment\excel\LayoutTest1ExcelTest.docm")
Else
Set oXB = oXA.Documents.Add("H:\proposalDocumentDevelopment\HVAC\experiment\excel\LayoutTest1ExcelTest.docm")
strOpenCheck = "added"
End If
Set rngExcelTest = oXB.Bookmarks("excelTest").Range
'If checked insert into bookmark excelTest
If Me.chkboxTest.Value = True Then
rngExcelTest = Cells(14, 4)
oXB.Bookmarks.Add "excelTest", rngExcelTest
Else 'clear bookmark
rngExcelTest = "off"
oXB.Bookmarks.Add "excelTest", rngExcelTest
End If
End Sub
However, the file which it is inserting data(H:\proposalDocumentDevelopment\HVAC\experimen t\excel\LayoutTest1ExcelTest.docm) is a sort of template and is therefore read only.
I did try having the user searching for a copy of the document but it would just ammend the document without showing it to the user. I also need to update the document several times within the one sitting so I cannot just use the add function as this kept bringing up multiple documents (each one having a different change on it.
I am not very experienced at VBA so could you please include fairly detailed comments.
Please help!
Thanks