CuddlyGoldfish
New Member
- Joined
- May 30, 2013
- Messages
- 8
Hi All,
I use MS 2007. I have an excel workbook with a number of named ranges and a word doc with a number of bookmarks. I am able to export the values in the named ranges to the corresponding bookmarks, and I can get the name of the doc to change to a specific name, but not the name I want, and it wont save to a location. I want the name of the doc to be the value in the range/bookmark "Name", followed by " Cert " followed by the current year.
My code is below, the save as part is at the end. Does anyone have any clever ideas?
Sub CertGenerator()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Dim Name As Excel.Range
Dim Start As Excel.Range
Dim Price As Excel.Range
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add(Template:="H:\Administration\Documentation\Templates\Cert Template 2013.docx")
Set Name = Sheets("Data Sheet").Range("Name")
Set Start = Sheets("Data Sheet").Range("Start")
Set Price = Sheets("Data Sheet").Range("Price")
With myDoc.Bookmarks
.Item("Name").Range.InsertAfter Name
.Item("Start").Range.InsertAfter Start
.Item("Price").Range.InsertAfter Price
End With
With wdApp.ActiveDocument
.SaveAs ThisWorkbook.Path & "Cert"
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub
I use MS 2007. I have an excel workbook with a number of named ranges and a word doc with a number of bookmarks. I am able to export the values in the named ranges to the corresponding bookmarks, and I can get the name of the doc to change to a specific name, but not the name I want, and it wont save to a location. I want the name of the doc to be the value in the range/bookmark "Name", followed by " Cert " followed by the current year.
My code is below, the save as part is at the end. Does anyone have any clever ideas?
Sub CertGenerator()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Dim Name As Excel.Range
Dim Start As Excel.Range
Dim Price As Excel.Range
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add(Template:="H:\Administration\Documentation\Templates\Cert Template 2013.docx")
Set Name = Sheets("Data Sheet").Range("Name")
Set Start = Sheets("Data Sheet").Range("Start")
Set Price = Sheets("Data Sheet").Range("Price")
With myDoc.Bookmarks
.Item("Name").Range.InsertAfter Name
.Item("Start").Range.InsertAfter Start
.Item("Price").Range.InsertAfter Price
End With
With wdApp.ActiveDocument
.SaveAs ThisWorkbook.Path & "Cert"
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub