Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2003 Data Import from SQL Lisa Excel Worksheet Functions 0 February 25th 08 09:37 AM
Eudora does not play nice with either Excel 2003 or Word 2003 Howard Kaikow Excel Programming 0 September 8th 07 03:58 PM
Copy and paste problem Excel 2003 to Word 2003 [email protected] Excel Discussion (Misc queries) 2 August 28th 07 11:14 AM
Import data from Outlook 2003 to Excel 2003 [email protected] Excel Programming 2 July 21st 07 03:06 AM
import Excel 2003 file into Outlook 2003 - NO NAMED RANGES?? lewisma9 Excel Discussion (Misc queries) 0 February 27th 07 12:23 AM


All times are GMT +1. The time now is 08:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"