View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 1,726
Default Macro - Open all word files in a directory

Personally, I would use late binding, a bit simpler

Dim wdApp As Object
Dim wdDoc As Object

'before the loop start
Set wdApp = CreateObject("Word.Application")
wdApp.Visible = True

'then within the loop
Set wdDoc = wdApp.Open(file.Path)
'Do your stuff here on wdDoc
wdDoc.Close SaveChanges:=True

'and after the loop
Set wdDoc = Nothing
wdApp.Quit
Set wdApp = Nothing


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Nick Hodge" wrote in message
...
Dileep

If you are just looking to automate Word, then, after setting a reference
to Microsoft Word library (as I use early binding), in the Excel VBE under
Tools (Code not tested)

Sub OpenWordandDoc()
Dim wdApp as Word.Application
Dim wdDoc as Word.Document
Set wdApp=New Word.Application
Set wdDoc=WdApp.Open("C:\Test.doc")
wdapp.Visible=True
'Do your stuff here
wdDoc.Close SaveChanges:=True
Set wdDoc=Nothing
wdApp.Quit
Set wdApp=Nothing
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"Dileep Chandran" wrote in message
ups.com...

Hi Bob,

I dont have much expertise in macro and VB, but if I get the code to
open a .doc file in a particular location, I can go ahead with the
balance.

Any way, thank you for your help. Revert back if you have any bright
ideas

Thanks & Regards
Dileep