Hi,

I'd like for word's File-Open & Save-As dialogs to point to the directory
from which I launched word. For example, I might just launch winword.exe from
the command line, say in directory: c:\abc\xyz in which case I'd like for
File-Open & Save-As to point to this directory. Could you point me to
suitable VBA source-code or inbuilt word menu options by which I can achieve
this ?

Thanks,
Anand.

Re: File Open Dialog based on startup directory by nc

nc
Sat Aug 20 05:48:36 CDT 2005

try sFilePath = ActiveDocument.Path
this should return the path of the current active document.



Norm


On Fri, 19 Aug 2005 19:12:13 -0700, "Anand"
<aanandgAThotmail.nospam.com> wrote:

>Thanks - but no, but this doesn't seem to work. This macro appears to set the
>file-open directory to the value specified by
>Tools->Options->FileLocations->Startup
>
>I realize now that my email title may be misleading since your solution does
>refer to a startup directory. What I'm looking for is the directory from
>which I launch winword.exe (assuming I launch it from the command line).
>Suppose the following commands are executed:
>
>c:\> cd abc\xyz
>c:\abc\xyz> winword.exe (assuming winword.exe is in the system path)
>
>Now I want the File-Open dialog box to point to c:\abc\xyz.
>
>-Anand.
>
>"Jezebel" wrote:
>
>> In theory,
>>
>> ChangeFileOpenDirectory CurDir
>>
>> not sure that it actually works, though.
>>
>>
>>
>> "Anand" <aanandgAThotmail.nospam.com> wrote in message
>> news:9291FC52-FD2F-40CB-BE50-23F7FFB2E884@microsoft.com...
>> > Hi,
>> >
>> > I'd like for word's File-Open & Save-As dialogs to point to the directory
>> > from which I launched word. For example, I might just launch winword.exe
>> > from
>> > the command line, say in directory: c:\abc\xyz in which case I'd like for
>> > File-Open & Save-As to point to this directory. Could you point me to
>> > suitable VBA source-code or inbuilt word menu options by which I can
>> > achieve
>> > this ?
>> >
>> > Thanks,
>> > Anand.
>>
>>
>>


Re: File Open Dialog based on startup directory by Steve

Steve
Sat Aug 20 18:53:51 CDT 2005

Anand,

If I understand correctly what you want to do, I think you need to create a
script that would accept the current directory as an argument and then
launch an instance of the Word Application Object which could then be
manipulated to set its file open directory as the argument fed the script.
Assuming you're using cmd.exe on an XP or Win2000 or 2003 PC, you could use
%cd% as the argument to your script which would deliver the current
directory you were camped in with cmd.exe. Your script (a vbs script would
work fine) would use WScript.Arguments.Item(0) to return the argument which
would be the path string.

If you just wanted to know the directory winword.exe was launched from,
Application.Path would do it but I think you actually wanted to use the
current directory you were in immediately prior to launching Word.

Steve


"Anand" <aanandgAThotmail.nospam.com> wrote in message
news:47DA6BFD-BD0E-4BFD-AC1F-E7AFE2BBE101@microsoft.com...
> Thanks - but no, but this doesn't seem to work. This macro appears to set
> the
> file-open directory to the value specified by
> Tools->Options->FileLocations->Startup
>
> I realize now that my email title may be misleading since your solution
> does
> refer to a startup directory. What I'm looking for is the directory from
> which I launch winword.exe (assuming I launch it from the command line).
> Suppose the following commands are executed:
>
> c:\> cd abc\xyz
> c:\abc\xyz> winword.exe (assuming winword.exe is in the system path)
>
> Now I want the File-Open dialog box to point to c:\abc\xyz.
>
> -Anand.
>
> "Jezebel" wrote:
>
>> In theory,
>>
>> ChangeFileOpenDirectory CurDir
>>
>> not sure that it actually works, though.
>>
>>
>>
>> "Anand" <aanandgAThotmail.nospam.com> wrote in message
>> news:9291FC52-FD2F-40CB-BE50-23F7FFB2E884@microsoft.com...
>> > Hi,
>> >
>> > I'd like for word's File-Open & Save-As dialogs to point to the
>> > directory
>> > from which I launched word. For example, I might just launch
>> > winword.exe
>> > from
>> > the command line, say in directory: c:\abc\xyz in which case I'd like
>> > for
>> > File-Open & Save-As to point to this directory. Could you point me to
>> > suitable VBA source-code or inbuilt word menu options by which I can
>> > achieve
>> > this ?
>> >
>> > Thanks,
>> > Anand.
>>
>>
>>



Re: File Open Dialog based on startup directory by Steve

Steve
Sat Aug 20 21:26:05 CDT 2005

Assuming my assumptions above are correct, try this. Create a new text file
named "myWord.vbs" and store in in your Windows folder or somewhere else in
the system path. Edit this text document to contain the following lines:

Dim fso, objWord
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists (WScript.Arguments.Item(0)) Then
MsgBox "You messed up the command line"
Else
Set objWord = CreateObject("Word.Application")
objWord.Application.ChangeFileOpenDirectory(Wscript.Arguments.Item(0))
objWord.Visible = True
End If

After saving the edited version of the vbs file, open cmd.exe. Change to
your preferred file open directory and then enter the line:
myWord "%cd%"
See if Word doesn't open with the default file open folder where you want.

Steve
"Anand" <aanandgAThotmail.nospam.com> wrote in message
news:47DA6BFD-BD0E-4BFD-AC1F-E7AFE2BBE101@microsoft.com...
> Thanks - but no, but this doesn't seem to work. This macro appears to set
> the
> file-open directory to the value specified by
> Tools->Options->FileLocations->Startup
>
> I realize now that my email title may be misleading since your solution
> does
> refer to a startup directory. What I'm looking for is the directory from
> which I launch winword.exe (assuming I launch it from the command line).
> Suppose the following commands are executed:
>
> c:\> cd abc\xyz
> c:\abc\xyz> winword.exe (assuming winword.exe is in the system path)
>
> Now I want the File-Open dialog box to point to c:\abc\xyz.
>
> -Anand.
>
> "Jezebel" wrote:
>
>> In theory,
>>
>> ChangeFileOpenDirectory CurDir
>>
>> not sure that it actually works, though.
>>
>>
>>
>> "Anand" <aanandgAThotmail.nospam.com> wrote in message
>> news:9291FC52-FD2F-40CB-BE50-23F7FFB2E884@microsoft.com...
>> > Hi,
>> >
>> > I'd like for word's File-Open & Save-As dialogs to point to the
>> > directory
>> > from which I launched word. For example, I might just launch
>> > winword.exe
>> > from
>> > the command line, say in directory: c:\abc\xyz in which case I'd like
>> > for
>> > File-Open & Save-As to point to this directory. Could you point me to
>> > suitable VBA source-code or inbuilt word menu options by which I can
>> > achieve
>> > this ?
>> >
>> > Thanks,
>> > Anand.
>>
>>
>>



Re: File Open Dialog based on startup directory by Jezebel

Jezebel
Sat Aug 20 21:55:45 CDT 2005

Steve, I think you've missed the point of the thread. First, if the user is
starting Word from within a given directory, that directory necessarily
exists, so there's no point in checking for that. Second,
ChangeFileOpenDirectory doesn't work for the required purpose.

Try this:

1. Start Word from the command line, in a folder that Word doesn't normally
use for opening or saving.

2. In Word's VBA immediate window, type : ? CurDir. You'll see the name of
the folder you started Word from.

3. type: ChangeFileOpenDirectory CurDir

4. Switch back to Word's main window and use File > Open.





"Steve Yandl" <syandl_nospam@comcast.net> wrote in message
news:BpWdnbWRp_-ge5reRVn-og@comcast.com...
> Assuming my assumptions above are correct, try this. Create a new text
> file named "myWord.vbs" and store in in your Windows folder or somewhere
> else in the system path. Edit this text document to contain the following
> lines:
>
> Dim fso, objWord
> Set fso = CreateObject("Scripting.FileSystemObject")
> If Not fso.FolderExists (WScript.Arguments.Item(0)) Then
> MsgBox "You messed up the command line"
> Else
> Set objWord = CreateObject("Word.Application")
> objWord.Application.ChangeFileOpenDirectory(Wscript.Arguments.Item(0))
> objWord.Visible = True
> End If
>
> After saving the edited version of the vbs file, open cmd.exe. Change to
> your preferred file open directory and then enter the line:
> myWord "%cd%"
> See if Word doesn't open with the default file open folder where you want.
>
> Steve
> "Anand" <aanandgAThotmail.nospam.com> wrote in message
> news:47DA6BFD-BD0E-4BFD-AC1F-E7AFE2BBE101@microsoft.com...
>> Thanks - but no, but this doesn't seem to work. This macro appears to set
>> the
>> file-open directory to the value specified by
>> Tools->Options->FileLocations->Startup
>>
>> I realize now that my email title may be misleading since your solution
>> does
>> refer to a startup directory. What I'm looking for is the directory from
>> which I launch winword.exe (assuming I launch it from the command line).
>> Suppose the following commands are executed:
>>
>> c:\> cd abc\xyz
>> c:\abc\xyz> winword.exe (assuming winword.exe is in the system path)
>>
>> Now I want the File-Open dialog box to point to c:\abc\xyz.
>>
>> -Anand.
>>
>> "Jezebel" wrote:
>>
>>> In theory,
>>>
>>> ChangeFileOpenDirectory CurDir
>>>
>>> not sure that it actually works, though.
>>>
>>>
>>>
>>> "Anand" <aanandgAThotmail.nospam.com> wrote in message
>>> news:9291FC52-FD2F-40CB-BE50-23F7FFB2E884@microsoft.com...
>>> > Hi,
>>> >
>>> > I'd like for word's File-Open & Save-As dialogs to point to the
>>> > directory
>>> > from which I launched word. For example, I might just launch
>>> > winword.exe
>>> > from
>>> > the command line, say in directory: c:\abc\xyz in which case I'd like
>>> > for
>>> > File-Open & Save-As to point to this directory. Could you point me to
>>> > suitable VBA source-code or inbuilt word menu options by which I can
>>> > achieve
>>> > this ?
>>> >
>>> > Thanks,
>>> > Anand.
>>>
>>>
>>>
>
>



Re: File Open Dialog based on startup directory by Steve

Steve
Sat Aug 20 22:11:35 CDT 2005

I understand exactly what you're saying and you're likely correct about what
the original poster is asking about. However, when I read the example that
the poster placed above my first post, I believe there is a chance that even
though he says he wants the file open directory to be the directory from
which he opened Word, I think he might actually mean that he might want Word
to recognize the current directory he was in under the command prompt
directory when he chose to launch Word.

He says,
>>> c:\abc\xyz> winword.exe (assuming winword.exe is in the system path)
>>>
>>> Now I want the File-Open dialog box to point to c:\abc\xyz.

I don't think he means that winword.exe is in c:\abc\xyz, rather, I think
c:\abc\xyz is an arbitrary path he wants to be able to navigate to and then
launch Word from the command prompt and have it recognize that he was in
c:\abc\xyz when he chose to do so.

Steve


"Jezebel" <warcrimes@whitehouse.gov> wrote in message
news:evloSvfpFHA.1948@TK2MSFTNGP12.phx.gbl...
> Steve, I think you've missed the point of the thread. First, if the user
> is starting Word from within a given directory, that directory necessarily
> exists, so there's no point in checking for that. Second,
> ChangeFileOpenDirectory doesn't work for the required purpose.
>
> Try this:
>
> 1. Start Word from the command line, in a folder that Word doesn't
> normally use for opening or saving.
>
> 2. In Word's VBA immediate window, type : ? CurDir. You'll see the name of
> the folder you started Word from.
>
> 3. type: ChangeFileOpenDirectory CurDir
>
> 4. Switch back to Word's main window and use File > Open.
>
>
>
>
>
> "Steve Yandl" <syandl_nospam@comcast.net> wrote in message
> news:BpWdnbWRp_-ge5reRVn-og@comcast.com...
>> Assuming my assumptions above are correct, try this. Create a new text
>> file named "myWord.vbs" and store in in your Windows folder or somewhere
>> else in the system path. Edit this text document to contain the
>> following lines:
>>
>> Dim fso, objWord
>> Set fso = CreateObject("Scripting.FileSystemObject")
>> If Not fso.FolderExists (WScript.Arguments.Item(0)) Then
>> MsgBox "You messed up the command line"
>> Else
>> Set objWord = CreateObject("Word.Application")
>> objWord.Application.ChangeFileOpenDirectory(Wscript.Arguments.Item(0))
>> objWord.Visible = True
>> End If
>>
>> After saving the edited version of the vbs file, open cmd.exe. Change to
>> your preferred file open directory and then enter the line:
>> myWord "%cd%"
>> See if Word doesn't open with the default file open folder where you
>> want.
>>
>> Steve
>> "Anand" <aanandgAThotmail.nospam.com> wrote in message
>> news:47DA6BFD-BD0E-4BFD-AC1F-E7AFE2BBE101@microsoft.com...
>>> Thanks - but no, but this doesn't seem to work. This macro appears to
>>> set the
>>> file-open directory to the value specified by
>>> Tools->Options->FileLocations->Startup
>>>
>>> I realize now that my email title may be misleading since your solution
>>> does
>>> refer to a startup directory. What I'm looking for is the directory from
>>> which I launch winword.exe (assuming I launch it from the command line).
>>> Suppose the following commands are executed:
>>>
>>> c:\> cd abc\xyz
>>> c:\abc\xyz> winword.exe (assuming winword.exe is in the system path)
>>>
>>> Now I want the File-Open dialog box to point to c:\abc\xyz.
>>>
>>> -Anand.
>>>
>>> "Jezebel" wrote:
>>>
>>>> In theory,
>>>>
>>>> ChangeFileOpenDirectory CurDir
>>>>
>>>> not sure that it actually works, though.
>>>>
>>>>
>>>>
>>>> "Anand" <aanandgAThotmail.nospam.com> wrote in message
>>>> news:9291FC52-FD2F-40CB-BE50-23F7FFB2E884@microsoft.com...
>>>> > Hi,
>>>> >
>>>> > I'd like for word's File-Open & Save-As dialogs to point to the
>>>> > directory
>>>> > from which I launched word. For example, I might just launch
>>>> > winword.exe
>>>> > from
>>>> > the command line, say in directory: c:\abc\xyz in which case I'd like
>>>> > for
>>>> > File-Open & Save-As to point to this directory. Could you point me to
>>>> > suitable VBA source-code or inbuilt word menu options by which I can
>>>> > achieve
>>>> > this ?
>>>> >
>>>> > Thanks,
>>>> > Anand.
>>>>
>>>>
>>>>
>>
>>
>
>



Re: File Open Dialog based on startup directory by Jezebel

Jezebel
Sat Aug 20 22:54:16 CDT 2005

I think he might actually mean that he might want Word
> to recognize the current directory he was in under the command prompt
> directory when he chose to launch Word.
>

That's what I think he meant, too. And although ChangeFileOpenDirectory
looks like it will set Word to use that directory, if you try it (as per my
example) you'll see it doesn't work for that purpose.




Re: File Open Dialog based on startup directory by Steve

Steve
Sat Aug 20 23:19:43 CDT 2005

If you try the script I submitted; it uses the ChangeFileOpenDirectory
method and it works as the original poster wanted (or the way we suspect he
wanted). When he launches winword.exe from the command prompt, he leaves
the cmd.exe or command.com process and winword.exe had no way to extract the
path info about the current directory status of the command interpreter
unless it is retained through a script or batch file.

Steve


"Jezebel" <warcrimes@whitehouse.gov> wrote in message
news:%23oRH$PgpFHA.3048@TK2MSFTNGP10.phx.gbl...
>I think he might actually mean that he might want Word
>> to recognize the current directory he was in under the command prompt
>> directory when he chose to launch Word.
>>
>
> That's what I think he meant, too. And although ChangeFileOpenDirectory
> looks like it will set Word to use that directory, if you try it (as per
> my example) you'll see it doesn't work for that purpose.
>
>
>



Re: File Open Dialog based on startup directory by Jezebel

Jezebel
Sun Aug 21 00:02:17 CDT 2005

Perhaps we're talking at cross-purposes. Of course you can extract the path
info: if you launch Word from the command line, eg in folder c:\XYZ, then in
Word VBA the CurDir function reports the name of that folder -- "C:\XYZ" as
expected. It's the ChangeFileOpenDirectory command that doesn't work.



"Steve Yandl" <syandl_nospam@comcast.net> wrote in message
news:OKCdnZELCplCnZXeRVn-1g@comcast.com...
> If you try the script I submitted; it uses the ChangeFileOpenDirectory
> method and it works as the original poster wanted (or the way we suspect
> he wanted). When he launches winword.exe from the command prompt, he
> leaves the cmd.exe or command.com process and winword.exe had no way to
> extract the path info about the current directory status of the command
> interpreter unless it is retained through a script or batch file.
>
> Steve
>
>
> "Jezebel" <warcrimes@whitehouse.gov> wrote in message
> news:%23oRH$PgpFHA.3048@TK2MSFTNGP10.phx.gbl...
>>I think he might actually mean that he might want Word
>>> to recognize the current directory he was in under the command prompt
>>> directory when he chose to launch Word.
>>>
>>
>> That's what I think he meant, too. And although ChangeFileOpenDirectory
>> looks like it will set Word to use that directory, if you try it (as per
>> my example) you'll see it doesn't work for that purpose.
>>
>>
>>
>
>



Re: File Open Dialog based on startup directory by Steve

Steve
Sun Aug 21 07:50:15 CDT 2005

I tested the script before posting and the line:
objWord.Application.ChangeFileOpenDirectory(Wscript.Arguments.Item(0))

does in fact cause the file open directory to be set to whatever the current
directory was for the cmd.exe console window when Word was launched from
that window.

Steve


"Jezebel" <warcrimes@whitehouse.gov> wrote in message
news:uJDj$1gpFHA.320@TK2MSFTNGP09.phx.gbl...
> Perhaps we're talking at cross-purposes. Of course you can extract the
> path info: if you launch Word from the command line, eg in folder c:\XYZ,
> then in Word VBA the CurDir function reports the name of that folder --
> "C:\XYZ" as expected. It's the ChangeFileOpenDirectory command that
> doesn't work.
>
>
>
> "Steve Yandl" <syandl_nospam@comcast.net> wrote in message
> news:OKCdnZELCplCnZXeRVn-1g@comcast.com...
>> If you try the script I submitted; it uses the ChangeFileOpenDirectory
>> method and it works as the original poster wanted (or the way we suspect
>> he wanted). When he launches winword.exe from the command prompt, he
>> leaves the cmd.exe or command.com process and winword.exe had no way to
>> extract the path info about the current directory status of the command
>> interpreter unless it is retained through a script or batch file.
>>
>> Steve
>>
>>
>> "Jezebel" <warcrimes@whitehouse.gov> wrote in message
>> news:%23oRH$PgpFHA.3048@TK2MSFTNGP10.phx.gbl...
>>>I think he might actually mean that he might want Word
>>>> to recognize the current directory he was in under the command prompt
>>>> directory when he chose to launch Word.
>>>>
>>>
>>> That's what I think he meant, too. And although ChangeFileOpenDirectory
>>> looks like it will set Word to use that directory, if you try it (as per
>>> my example) you'll see it doesn't work for that purpose.
>>>
>>>
>>>
>>
>>
>
>



Re: File Open Dialog based on startup directory by aanandgAThotmail

aanandgAThotmail
Tue Sep 20 16:16:02 CDT 2005

Thanks Steve. This worked out nicely. In addition to your vbscript, I created
another launch.bat file that says: myword "%cd%". So I dont have to type in
the extra "%cd%" either..

One small problem I have is that the instance of word window that gets
launched doesn't have focus.. I need to "click" on the word window before I
can say Crtl-N, Ctrl-O, etc.. pls let me know if this can be solved simply
within the script itself (clearly I'm not a VB guy :)

Thanks!

"Steve Yandl" wrote:

> Assuming my assumptions above are correct, try this. Create a new text file
> named "myWord.vbs" and store in in your Windows folder or somewhere else in
> the system path. Edit this text document to contain the following lines:
>
> Dim fso, objWord
> Set fso = CreateObject("Scripting.FileSystemObject")
> If Not fso.FolderExists (WScript.Arguments.Item(0)) Then
> MsgBox "You messed up the command line"
> Else
> Set objWord = CreateObject("Word.Application")
> objWord.Application.ChangeFileOpenDirectory(Wscript.Arguments.Item(0))
> objWord.Visible = True
> End If
>
> After saving the edited version of the vbs file, open cmd.exe. Change to
> your preferred file open directory and then enter the line:
> myWord "%cd%"
> See if Word doesn't open with the default file open folder where you want.
>
> Steve
> "Anand" <aanandgAThotmail.nospam.com> wrote in message
> news:47DA6BFD-BD0E-4BFD-AC1F-E7AFE2BBE101@microsoft.com...
> > Thanks - but no, but this doesn't seem to work. This macro appears to set
> > the
> > file-open directory to the value specified by
> > Tools->Options->FileLocations->Startup
> >
> > I realize now that my email title may be misleading since your solution
> > does
> > refer to a startup directory. What I'm looking for is the directory from
> > which I launch winword.exe (assuming I launch it from the command line).
> > Suppose the following commands are executed:
> >
> > c:\> cd abc\xyz
> > c:\abc\xyz> winword.exe (assuming winword.exe is in the system path)
> >
> > Now I want the File-Open dialog box to point to c:\abc\xyz.
> >
> > -Anand.
> >
> > "Jezebel" wrote:
> >
> >> In theory,
> >>
> >> ChangeFileOpenDirectory CurDir
> >>
> >> not sure that it actually works, though.
> >>
> >>
> >>
> >> "Anand" <aanandgAThotmail.nospam.com> wrote in message
> >> news:9291FC52-FD2F-40CB-BE50-23F7FFB2E884@microsoft.com...
> >> > Hi,
> >> >
> >> > I'd like for word's File-Open & Save-As dialogs to point to the
> >> > directory
> >> > from which I launched word. For example, I might just launch
> >> > winword.exe
> >> > from
> >> > the command line, say in directory: c:\abc\xyz in which case I'd like
> >> > for
> >> > File-Open & Save-As to point to this directory. Could you point me to
> >> > suitable VBA source-code or inbuilt word menu options by which I can
> >> > achieve
> >> > this ?
> >> >
> >> > Thanks,
> >> > Anand.
> >>
> >>
> >>
>
>
>