HollyLouise
New Member
- Joined
- Feb 7, 2013
- Messages
- 3
Hello All,
New to forum and new to VBA, so any comments would be appeciated. I want excel to open a word document template and place a information in a cell into the word document in between two words. (I write many reports and opposed to writing all the information into excel then word as I do now, I want a template in excel and a word template that will update as I change information in excel). I bookmarked the word which I want replaced in the word document "details" and asked excel to replace it with the value in the cell but it keeps saying Compile Error: sub or function not defined.
I want to reiterate, that I am a complete beginner to this, so any comments would much be appreciated.
My code is saved into a module in VBA and is
Private Sub importExcelData()
Dim wdApp As Object
Dim wdDoc As Object
Dim workBook As workBook
Dim dataInExcel As String
Application.ScreenUpdating = False
Set workBook = Workbooks.Open("C:\Holly\Spreadsheet\123.xls", True, True)
Edit "C:\Holly\Spreadsheet\123.xls"
dataInExcel = workBook.Worksheets("Details").Range("B2").Formula
Selection.TypeParagraph
Selection.TypeText Text:=dataInExcel
'open the word documents
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open("C:\Holly\Template.docx")
'replace the bookmarks with the variables
FillBookmark wdDoc, sName, "Details"
'show the word document
wdApp.Visible = True
End Sub
New to forum and new to VBA, so any comments would be appeciated. I want excel to open a word document template and place a information in a cell into the word document in between two words. (I write many reports and opposed to writing all the information into excel then word as I do now, I want a template in excel and a word template that will update as I change information in excel). I bookmarked the word which I want replaced in the word document "details" and asked excel to replace it with the value in the cell but it keeps saying Compile Error: sub or function not defined.
I want to reiterate, that I am a complete beginner to this, so any comments would much be appreciated.
My code is saved into a module in VBA and is
Private Sub importExcelData()
Dim wdApp As Object
Dim wdDoc As Object
Dim workBook As workBook
Dim dataInExcel As String
Application.ScreenUpdating = False
Set workBook = Workbooks.Open("C:\Holly\Spreadsheet\123.xls", True, True)
Edit "C:\Holly\Spreadsheet\123.xls"
dataInExcel = workBook.Worksheets("Details").Range("B2").Formula
Selection.TypeParagraph
Selection.TypeText Text:=dataInExcel
'open the word documents
Set wdApp = CreateObject("Word.Application")
Set wdDoc = wdApp.Documents.Open("C:\Holly\Template.docx")
'replace the bookmarks with the variables
FillBookmark wdDoc, sName, "Details"
'show the word document
wdApp.Visible = True
End Sub