![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Apr 2002
Posts: 22
|
Hi ! I'm looking for a macro or a way to export info from a cell in MsExcel to a cell in a form in MsWord.
Thanks ! |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Apr 2002
Posts: 113
|
Probably easier the other way around. Import the information from Excel into Word.
Try simple links. 1) Create your XLS 2) Create your DOC 3) One at a time, paste link each cell from the XLS into the appropriate place in the DOC. If you have a table of data on sheet 1 in the XLS that you want to create several forms from, then the linked XLS cells should be on sheet 2 (for ex.) The cells on sheet 2 would contain Vlookup (or similar) equations that will lookup the information from the table. The Vlookup would look at a cell on sheet 2 to determine which row to obtain from the table. Now, If that cell can be a link pasted from the word doc, then if you change the name in the word doc, then update excel, then update word, you should be able to page through the table from word. I have never tried this, but it should work. I expect that someone else could offer you a slicker VBA way of do this. Ex: DOC============== NAME: John DATE OF BIRTH: = [c:/dir/file.xls]Sheet2!$B$2 CITY OF BIRTH: = [c:/dir/file.xls]Sheet2!$B$3 XLS SHEET 1============= NAME DATE OF BIRTH CITY OF BIRTH John 1909 San Francisco Frank 1999 New York etc. XLS SHEET 2============ A1(NAME)=C:/dir/file.doc ..?. (manually paste link) B1(NAME) =vlookup(A1,Sheet1Table,1) B2(DATE OF BIRTH) =vlookup(A1,Sheet1Table,2) etc. Cheers, Brian |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Posts: 3,065
|
if you need code check the Microsoft file thats default installed with office
samples.xls
__________________
Free Excel based Web Toolbar available here. Jack in the UK J & R Excel Solutions "making Excel work for you" |
|
|
|
|
|
#4 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
You can play with the following sample code:
Code:
Sub WordUp()
Dim WdObj As Object, fname As String
fname = Sheets(2).[a1].Value
Set WdObj = CreateObject("Word.Application")
WdObj.Visible = False
Sheets(1).UsedRange.Copy
WdObj.documents.Add
WdObj.Selection.Paste
Application.CutCopyMode = False
If fname <> "" Then 'make sure fname is not blank
With WdObj
.ChangeFileOpenDirectory "c:temp"
.ActiveDocument.SaveAs Filename:=fname & ".doc"
End With
Else:
MsgBox ("File not saved, naming range was botched, guess again.")
End If
With WdObj
.ActiveDocument.Close False
.Quit
End With
Set WdObj = Nothing
End Sub
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Posts: 3,065
|
NAte has given nice code more of less the sane as samples it creates word as an object...
__________________
Free Excel based Web Toolbar available here. Jack in the UK J & R Excel Solutions "making Excel work for you" |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|