Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting the file path of document dynamically

Status
Not open for further replies.

monak

MIS
Jul 2, 2002
22
US
I am running a macro through the normal.dot file. What I want to do is assign ActiveDocument.path to a variable. But when I do this I the error "Invalid Outside Procedure". What am I doing wrong?



My code:

path2file = ActiveDocument.path

sfile = FreeFile
Open path2file For Input As #sfile

Do While Not EOF(sfile)
intLine = intLine + 1
Line Input #sfile, strbuffer
LookforKeywords strbuffer
Loop
Close #sfile
ActiveDocument.Close
End Sub
 
Not sure what line you get error on.

Have you tried Application.ActiveDocument.Path
Example c:\myfolder
This gives the path of the active document
Application.ActiveDocument.Name gives the name of the active document
Example Filename.doc

You must make sure the file has been saved first or you will not get any useful data back (try if Application.ActiveDocument.Saved=true)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top