Can VBA open docs from filepath and run an action?

S

Sydney

Hi all

I am trying to open all documents from a filepath, run a macro that deletes
the watermark, save and close the document. Is this possible.

What I have so far errors as marked below:

Sub Test()

Dim Odoc As Word.Documents

Set fs = Application.FileSearch
With fs
.LookIn = path '"C:\"
.FileName = "*.doc"
' ' .Open (fail)

End With

For Each Odoc In fs ' I get an error here, Object doesnt support
this property
Call DeleteGraphic
Odoc.save
Odoc.close
Next Odoc

'End With
End Sub

Thanks in advance
 
E

Edward Thrashcort

Use the Dir() statement and open the document by name something like this

ChangeFileOpenDirectory "C:\My Documents"
f = Dir("*.doc")
While f <> ""
Documents.Open Filename:=f
'do the business
ActiveDocument.Close SaveChanges:=wdSaveChanges
f = Dir()
Wend


Eddie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top