I have a rather complex spreadsheet that is used by many users. After filling in data, they need to prepare a document in Word. Using Mail Merge is not an option since I've found most users get tripped up. I want to create a button that automates the entire process. I have created a Word Document with bookmarks where the data needs to be inserted and matching range names in the Excel spreadsheet.
I've created a macro (see below) in Excel which works when I'm running it on Windows 8 and Excel 2013, however, many of the users are running Windows 7 and Excel 2010. The macro crashes in that environment. Not being an expert in VBA, I could use some help to find what I'm doing wrong and find a script that will work in Windows 7 and 8 as well as Excel 2010 and 2013.
Note that I have enabled the Microsoft Word Object Library in Excel on all computers that are using this macro. Shown below is what I've got. There are 3 main sections:
The First part allows the user to select the Word Document they want to link to (this is because each user may save it in a different location)
The Second Part links the bookmarks to range names
The Final Part copies a table from the Excel Spreadsheet and pastes it into the appropriate section in Word.
Sub FeedWordDoc()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim EQTrange As Excel.Range
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Dialogs(wdDialogFileOpen).Show
Set wrdDoc = ActiveDocument
Set EQTrange = Sheets("PROPOSAL").Range("EQT")
EQTrange.Copy
'BEGIN TRANSFERRING FIELDS TO WORD
With wrdDoc
wrdDoc.Bookmarks("ProjType").Range.Text = Range("ProjType").Text
wrdDoc.Bookmarks("ProposalCo").Range.Text = Range("ProposalCo").Text
wrdDoc.Bookmarks("ProposalStrAndSuite").Range.Text = Range("PropStrAndSuite").Text
wrdDoc.Bookmarks("ProposalCSZ").Range.Text = Range("ProposalCSZ").Text
wrdDoc.Bookmarks("D_StrAndSuite").Range.Text = Range("D_StrAndSuite").Text
wrdDoc.Bookmarks("D_CSZ").Range.Text = Range("D_CSZ").Text
wrdDoc.Bookmarks("BillingToCo").Range.Text = Range("BillingCompany").Text
wrdDoc.Bookmarks("BillStrAndSuite").Range.Text = Range("BillStrAndSuite").Text
wrdDoc.Bookmarks("BillingCSZ").Range.Text = Range("BillingCSZ").Text
wrdDoc.Bookmarks("SiteName").Range.Text = Range("SitePlusName").Text
wrdDoc.Bookmarks("SiteContact").Range.Text = Range("SiteContact").Text
wrdDoc.Bookmarks("SiteEmail").Range.Text = Range("siteEmail").Text
wrdDoc.Bookmarks("SiteStrAndSuite").Range.Text = Range("SiteStrAndSuite").Text
wrdDoc.Bookmarks("SiteCSZ").Range.Text = Range("SiteCSZ").Text
wrdDoc.Bookmarks("SitePhone").Range.Text = Range("SitePhone").Text
wrdDoc.Bookmarks("ProjTypeAgain").Range.Text = Range("ProjType").Text
wrdDoc.Bookmarks("C_Price").Range.Text = Range("C_Price").Text
wrdDoc.Bookmarks("C_PriceVerb").Range.Text = Range("C_PriceVerb").Text
wrdDoc.Bookmarks("S_Price").Range.Text = Range("S_Price").Text
End With
'
'NOW TRANSFER THE PARTS LIST
wrdDoc.Bookmarks("EQT").Range.PasteExcelTable False, False, False
'
Set wrdDoc = Nothing
Set wrdApp = Nothing
'
End Sub
Bookmarks