Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Filling a Word form from an Excel spreadsheet

This must be quite a routine job but I haven't found a
good example anywhere.
I have an Excel worksheet containing data that will be
exported to a Word document which in fact is a form. My
VBA-program should open the Word document, export the
data to the correct locations in the form, save the form
under a new filename and close the Word documents.
Any examples coming close to solving this problem?
Thanks,
Roel
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default Filling a Word form from an Excel spreadsheet

If you have bookmarks in the Word document, you could use a macro
similar to the following:

'===========================
Sub CopyToWord()
'set a reference to Word
' -- in VBE, choose ToolsReferences
Dim ws As Worksheet
Dim r As Long
Dim WdApp As Object
Dim strPath As String
Dim strFile As String
Dim strFileNew As String
Dim doc As Object
Set ws = Sheets("Sheet1")

strPath = "C:\Data\"
strFile = "Test.doc"
strFileNew = "TestNew.doc"

On Error Resume Next
Set WdApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Err.Clear
Set WdApp = CreateObject("Word.Application")
End If

On Error GoTo 0
WdApp.Documents.Open Filename:=strPath & strFile, _
ConfirmConversions:=False, ReadOnly:=False
Set doc = WdApp.activedocument
WdApp.Visible = True

With WdApp
.Selection.Goto What:=wdGoToBookmark, Name:="bkmk1"
.Selection.TypeText Text:=CStr(ws.Range("Field01").Value)

.Selection.Goto What:=wdGoToBookmark, Name:="bkmk2"
.Selection.TypeText Text:=CStr(ws.Range("Field02").Value)
End With

doc.SaveAs Filename:=strPath & strFileNew
doc.Close SaveChanges:=wdSaveChanges
Set WdApp = Nothing

End Sub
'======================================

Roel wrote:
This must be quite a routine job but I haven't found a
good example anywhere.
I have an Excel worksheet containing data that will be
exported to a Word document which in fact is a form. My
VBA-program should open the Word document, export the
data to the correct locations in the form, save the form
under a new filename and close the Word documents.
Any examples coming close to solving this problem?
Thanks,
Roel



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Filling a Word form from an Excel spreadsheet

Thanks, Debra. This is of great help.
Roel

-----Original Message-----
If you have bookmarks in the Word document, you could

use a macro
similar to the following:

'===========================
Sub CopyToWord()
'set a reference to Word
' -- in VBE, choose ToolsReferences
Dim ws As Worksheet
Dim r As Long
Dim WdApp As Object
Dim strPath As String
Dim strFile As String
Dim strFileNew As String
Dim doc As Object
Set ws = Sheets("Sheet1")

strPath = "C:\Data\"
strFile = "Test.doc"
strFileNew = "TestNew.doc"

On Error Resume Next
Set WdApp = GetObject(, "Word.Application")
If Err.Number < 0 Then
Err.Clear
Set WdApp = CreateObject("Word.Application")
End If

On Error GoTo 0
WdApp.Documents.Open Filename:=strPath & strFile, _
ConfirmConversions:=False, ReadOnly:=False
Set doc = WdApp.activedocument
WdApp.Visible = True

With WdApp
.Selection.Goto What:=wdGoToBookmark, Name:="bkmk1"
.Selection.TypeText Text:=CStr(ws.Range

("Field01").Value)

.Selection.Goto What:=wdGoToBookmark, Name:="bkmk2"
.Selection.TypeText Text:=CStr(ws.Range

("Field02").Value)
End With

doc.SaveAs Filename:=strPath & strFileNew
doc.Close SaveChanges:=wdSaveChanges
Set WdApp = Nothing

End Sub
'======================================

Roel wrote:
This must be quite a routine job but I haven't found a
good example anywhere.
I have an Excel worksheet containing data that will be
exported to a Word document which in fact is a form.

My
VBA-program should open the Word document, export the
data to the correct locations in the form, save the

form
under a new filename and close the Word documents.
Any examples coming close to solving this problem?
Thanks,
Roel



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Filling a Word form from an Excel spreadsheet


http://support.microsoft.com/support.../Q123/8/59.asp
ACC: Sample OLE Automation for MS Word and MS Excel

http://support.microsoft.com/support...aqVBOffice.asp
Frequently Asked Questions about Microsoft Office Automation Using Visual
Basic

http://support.microsoft.com/support...fdevinapps.asp
Programming Office from Within Office

http://support.microsoft.com/default...83&Product=xlw
How to Create a Form Letter with a Visual Basic Macro

http://support.microsoft.com/default...16&Product=xlw
XL2000: Macro to Link a Range of Cells in Word

http://support.microsoft.com/default...74&Product=xlw
OFF: How to Use (OLE) Automation with Word

--
Regards,
Tom Ogilvy


"Roel" wrote in message
...
This must be quite a routine job but I haven't found a
good example anywhere.
I have an Excel worksheet containing data that will be
exported to a Word document which in fact is a form. My
VBA-program should open the Word document, export the
data to the correct locations in the form, save the form
under a new filename and close the Word documents.
Any examples coming close to solving this problem?
Thanks,
Roel



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Filling a Word form from an Excel spreadsheet

Thanks, Tom. I'm trying to find my way here. Your help is
much appreciated.

Roel

-----Original Message-----

http://support.microsoft.com/support...icles/Q123/8/5

9.asp
ACC: Sample OLE Automation for MS Word and MS Excel

http://support.microsoft.com/support...Dev/FaqVBOffic

e.asp
Frequently Asked Questions about Microsoft Office

Automation Using Visual
Basic

http://support.microsoft.com/support...Dev/offdevinap

ps.asp
Programming Office from Within Office

http://support.microsoft.com/default.aspx?scid=kb;en-

us;138283&Product=xlw
How to Create a Form Letter with a Visual Basic Macro

http://support.microsoft.com/default.aspx?scid=kb;en-

us;213316&Product=xlw
XL2000: Macro to Link a Range of Cells in Word

http://support.microsoft.com/default.aspx?scid=kb;en-

us;184974&Product=xlw
OFF: How to Use (OLE) Automation with Word

--
Regards,
Tom Ogilvy


"Roel" wrote in

message
...
This must be quite a routine job but I haven't found a
good example anywhere.
I have an Excel worksheet containing data that will be
exported to a Word document which in fact is a form. My
VBA-program should open the Word document, export the
data to the correct locations in the form, save the

form
under a new filename and close the Word documents.
Any examples coming close to solving this problem?
Thanks,
Roel



.



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
Fill out Word template form from Excel spreadsheet YiChing Excel Discussion (Misc queries) 1 March 31st 09 10:53 PM
visual basic help Excel/word form filling in laandmc Excel Discussion (Misc queries) 1 September 25th 08 01:12 PM
transfering data from word form to an existing spreadsheet Jose Excel Discussion (Misc queries) 1 October 15th 07 07:56 PM
filling a form in Excel... lookup? maybe? bigwerdz Excel Discussion (Misc queries) 2 September 29th 06 04:18 PM
Put form fields in Word forms into an Excel spreadsheet? AMG Excel Discussion (Misc queries) 4 May 15th 06 06:18 AM


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

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

About Us

"It's about Microsoft Excel"