Archive of Mr Excel Message Board


Back to Other Office and Excel archive index
Back to archive home

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


Maybe....

Posted by Dan on December 04, 2001 7:11 AM
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


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

Posted by Dwight on December 04, 2001 7:37 AM
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.

Try removing the ".Value"

Posted by Dan on December 04, 2001 7:51 AM
Change the line to:
fileName = Selection

See what that does.


Bingo! Thanks, Dan

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


This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.