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

1. I am opening Word through Excel (No problem)
2. Adding a new document in Word (No problem)
3. Trying to insert Wordfiles stored on disc into new created document by:

oDoc.Selection.InsertFile FileName:=MyFile, Link:=False

The program does not accept the line above. Why?

Here is the total program:
Sub InsertWordFiles()
'Inserts all Wordfiles in "C:\Temp" into a new created Worddocument
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim MyFile As String

'Open Word and add a new document
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Add

'Add all Wordfiles in "C\Temp" into new created Wordfile
ChDir "C:\Temp"
MyFile = Dir("*.doc")
Do
oDoc.Selection.InsertFile FileName:=MyFile, Link:=False
MyFile = Dir
Loop Until MyFile = Empty
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Control Word through Excel

Jocke

What do you mean by "not accept"

This works

Sub test()

Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Dim sPath As String
Dim sFile As String

sPath = "C:\Dick\NG\01 Jan\"

Set wdApp = New Word.Application
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Add

sFile = Dir(sPath & "*.doc")

Do While Len(sFile) 0
wdDoc.Range.InsertFile sPath & sFile, , , False
sFile = Dir
Loop

End Sub

Maybe it has something to do with the default path. Try storing the path in
a variable like I do instead of using ChDir.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Jocke wrote:
1. I am opening Word through Excel (No problem)
2. Adding a new document in Word (No problem)
3. Trying to insert Wordfiles stored on disc into new created
document by:

oDoc.Selection.InsertFile FileName:=MyFile, Link:=False

The program does not accept the line above. Why?

Here is the total program:
Sub InsertWordFiles()
'Inserts all Wordfiles in "C:\Temp" into a new created Worddocument
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim MyFile As String

'Open Word and add a new document
Set oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Add

'Add all Wordfiles in "C\Temp" into new created Wordfile
ChDir "C:\Temp"
MyFile = Dir("*.doc")
Do
oDoc.Selection.InsertFile FileName:=MyFile, Link:=False
MyFile = Dir
Loop Until MyFile = Empty
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 macro to control Word Problem Dave R[_3_] Excel Programming 5 July 31st 04 10:35 PM
Word Control in Excel Stuart[_5_] Excel Programming 10 July 11th 04 08:47 PM
how to control word from excel Torstein S. Johnsen[_2_] Excel Programming 1 February 10th 04 02:10 PM
Print Control in Word/Excel Charles Maxson Excel Programming 0 December 30th 03 08:55 PM
Print Control in Word/Excel losmac[_2_] Excel Programming 0 December 30th 03 08:22 PM


All times are GMT +1. The time now is 04:15 AM.

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"