MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Can someone help w/ a Word question?


Posted by Dwight on December 04, 2001 5:54 AM

Alright, I know it's not Excel but I don't know where else to go for an answer.

I have a directory called “Notes” (full path below) which contains files for making quick notes on telephone conversations with clients. Each filename is one word name for client. I want to be able to type the name and run a macro which will cut the name, open to the “Notes” directory, paste the name in the “file name” section of the “File Open” dialog box, and open the file.

Tried to record but the macro (see below) always opens the file (“Romain”) I used for recording. Can someone help?


Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.Cut
ChangeFileOpenDirectory "\\EVA001\#114008\Docmnts\CUSTOMER\Notes\"
Documents.Open FileName:="romain.doc", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=wdOpenFormatAuto


Posted by Dan on December 04, 2001 7:11 AM

Maybe....

I've never done any VBA in Word, but the reason you are always getting the romain file is because it is hard coded in your macro. Try this and let me know if it works. If so, it will be my first Word macro!

Dim fileName as String
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
fileName = Selection.Value
ChangeFileOpenDirectory "\\EVA001\#114008\Docmnts\CUSTOMER\Notes\"
Documents.Open FileName:="" & fileName & ".doc", ConfirmConversions:=False, ReadOnly _
:=False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate _
:="", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="" _
, Format:=wdOpenFormatAuto

Posted by Dwight on December 04, 2001 7:37 AM

Dan: Hit a snag .......

When I run it I get an error message: "Compile error: Method or data member not found, and the word "Value" in the 3rd line of your suggested code is highlighted. Tried with 2 different file names Any ideas for a fix?
Either way, I appreciate the attempt.

Posted by Dan on December 04, 2001 7:51 AM

Try removing the ".Value"

Change the line to:
fileName = Selection

See what that does.

Posted by Dwight on December 04, 2001 9:03 AM

Bingo! Thanks, Dan