Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Control Word Files From Excel

I have been successful in moving data from Excel to Word in VB. From Excel
(2003 running on Windows XP Pro) I am able to create several Word files from
the same starting Word form. Now, using Excel VB, I need to connect these
files into one Word report and have three questions.

1) End of document
I need to move the insertion point to the end of the first file before I
insert the second file. Ive recorded a macro in Word and tried the following:
WordApp.ActiveDocument.Selection.EndKey Unit:=6
But it does not work. Do you know what will work? Please provide code
examples.

2) Append Files
Then I need to append the next file. From the same Word macro I recorded I
have tried:
WordApp.ActiveDocument.Selection.InsertFile Filename:="File1.doc"
But it does not work. Do you know what will work? Please provide code
examples.

3) Insert Text
After they are all appended together, I need to insert some text before I
save and close the file. From the same Word macro I recorded I have tried:
WordApp.ActiveDocument.Selection.TypeText Text:="Text to be inserted"
But it does not work. Do you know what will work? Please provide code
examples.

Many Thanks
M

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Control Word Files From Excel

Hi,

an example how to loop through every word files in a given folder
and add then content of each file in a new document.
I separated each content by a line showing the document name


'------------------------------------------------
Sub test()
Dim Wd As Object, MyDoc As Object
Dim Rg As Object, Dc As Object
Dim MyPath As String, DocName As Object
Dim MyFile As String

MyPath = "c:\Users\Your_Profile\Documents\"
MyFile = Dir(MyPath & "*.do*")

Application.ScreenUpdating = False

Set Wd = CreateObject("Word.Application")
Wd.Visible = True
Set MyDoc = Wd.Documents.Add

Do While MyFile < ""
Set Dc = Wd.Documents.Open(MyPath & MyFile)
Set Rg = MyDoc.Content
Rg.Paragraphs.Add
Rg.InsertAfter Dc.Name
Set DocName = Rg.Paragraphs(Rg.Paragraphs.Count).Range
With DocName
.Font.Bold = True
.Font.Size = 14
.Font.Color = vbBlue
End With
Rg.Paragraphs.Add
Set DocName = Rg.Paragraphs(Rg.Paragraphs.Count).Range
With DocName
.Font.Bold = False
.Font.Size = 11
.Font.Color = wdColorAutomatic
End With
Rg.InsertAfter Dc.Content
Dc.Close False
MyFile = Dir()
Loop
Application.ScreenUpdating = True
End Sub
'------------------------------------------------



"Modeerf60" a écrit dans le message de groupe de
discussion : ...
I have been successful in moving data from Excel to Word in VB. From Excel
(2003 running on Windows XP Pro) I am able to create several Word files from
the same starting Word form. Now, using Excel VB, I need to connect these
files into one Word report and have three questions.

1) End of document
I need to move the insertion point to the end of the first file before I
insert the second file. Ive recorded a macro in Word and tried the following:
WordApp.ActiveDocument.Selection.EndKey Unit:=6
But it does not work. Do you know what will work? Please provide code
examples.

2) Append Files
Then I need to append the next file. From the same Word macro I recorded I
have tried:
WordApp.ActiveDocument.Selection.InsertFile Filename:="File1.doc"
But it does not work. Do you know what will work? Please provide code
examples.

3) Insert Text
After they are all appended together, I need to insert some text before I
save and close the file. From the same Word macro I recorded I have tried:
WordApp.ActiveDocument.Selection.TypeText Text:="Text to be inserted"
But it does not work. Do you know what will work? Please provide code
examples.

Many Thanks
M

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
Navigating to Excel files over network slow, but not Word files Newbie123 Excel Discussion (Misc queries) 1 December 2nd 09 01:18 PM
I want to attach word files or PDF files to an excel database Dianne Munro Excel Discussion (Misc queries) 1 March 23rd 06 12:11 AM
changing word files to excel files charlie'smom Excel Discussion (Misc queries) 2 August 12th 05 02:28 PM
Word Control in Excel Stuart[_5_] Excel Programming 10 July 11th 04 08:47 PM
convert 400 word files to excel files fast? CPower[_13_] Excel Programming 1 June 21st 04 10:29 AM


All times are GMT +1. The time now is 05:39 AM.

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"