Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Import Excel 2003 data into Word 2003
Hello all, I am trying to write a macro in a Word 2003 document that will
allow the user to import some data from an Excel 2003 spreadsheet. I got started with trying to "MailMerge" using the code below but all it does is open a BLANK, new word document and it does not import anything from the Excel sheet. Any ideas? Is MailMerge the wrong direction to go with this? Thanks in advace for the help. Sub ImportDatafromExcelintoWord() Dim docNew As Document Set docNew = Documents.Add With docNew.MailMerge .MainDocumentType = wdNotAMergeDocument .OpenDataSource Name:="C:\Data\ExcelImportData.xls", _ ReadOnly:=True, _ Connection:="CustomerData" End With End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Import Excel 2003 data into Word 2003
Take a look at this:
http://word.mvps.org/FAQs/InterDev/C...WordFromXL.htm This too: http://addbalance.com/usersguide/fields.htm And this: http://gregmaxey.mvps.org/Word_Fields.htm Finally, once you get the DocVariable fields set up in Word (hit Alt + F9 to see all fields), run this code from Excel. Sub PushToWord() Dim objWord As New Word.Application Dim doc As Word.Document Dim bkmk As Word.Bookmark sWdFileName = Application.GetOpenFilename(, , , , False) Set doc = objWord.Documents.Open(sWdFileName) With doc ..Variables("VarNumber1").Value = Range("VarNumber1").Value ..Variables("VarNumber2").Value = Range("VarNumber2").Value 'etc ..Range.Fields.Update End With 'ActiveDocument.Fields.Update objWord.Visible = True End Sub Note: This code runs in Excel; pushes Excel variables (assigned as Named Ranges) to Word. HTH, Ryan--- -- Ryan--- If this information was helpful, please indicate this by clicking ''Yes''. "statum" wrote: Hello all, I am trying to write a macro in a Word 2003 document that will allow the user to import some data from an Excel 2003 spreadsheet. I got started with trying to "MailMerge" using the code below but all it does is open a BLANK, new word document and it does not import anything from the Excel sheet. Any ideas? Is MailMerge the wrong direction to go with this? Thanks in advace for the help. Sub ImportDatafromExcelintoWord() Dim docNew As Document Set docNew = Documents.Add With docNew.MailMerge .MainDocumentType = wdNotAMergeDocument .OpenDataSource Name:="C:\Data\ExcelImportData.xls", _ ReadOnly:=True, _ Connection:="CustomerData" End With End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Excel 2003 Data Import from SQL | Excel Worksheet Functions | |||
Eudora does not play nice with either Excel 2003 or Word 2003 | Excel Programming | |||
Copy and paste problem Excel 2003 to Word 2003 | Excel Discussion (Misc queries) | |||
Import data from Outlook 2003 to Excel 2003 | Excel Programming | |||
import Excel 2003 file into Outlook 2003 - NO NAMED RANGES?? | Excel Discussion (Misc queries) |