Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

VBA Word: How to point to a specific dir when a file dialog opens up?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sharon3874 - 20 Dec 2006 01:01 GMT
in VBA word, when I right click on some text, I can add hyperlinks upon
the text. It will open up a file dialog(window) allowing me to navigate
and pick a file. My question is that how I can force the dialog box to
point to a certain directory when it opens up?

Thanks a lot.
Doug Robbins - Word MVP - 20 Dec 2006 08:51 GMT
Create a macro with the name InsertHyperlink() and it will then run when you
right click and select Hyperlink.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> in VBA word, when I right click on some text, I can add hyperlinks upon
> the text. It will open up a file dialog(window) allowing me to navigate
> and pick a file. My question is that how I can force the dialog box to
> point to a certain directory when it opens up?
>
> Thanks a lot.
sharon3874 - 20 Dec 2006 15:44 GMT
I am sorry, can you explain this in more detail?

Thanks a lot.

> Create a macro with the name InsertHyperlink() and it will then run when you
> right click and select Hyperlink.
Greg Maxey - 20 Dec 2006 17:21 GMT
Doug,

I think what Sharon is trying to do is create a macro that displays the
InsertHyperlink dialog with a specific "look in" folder selected.

If it is possible, I assume it would start out something like:

Sub test()
With Dialogs(wdDialogInsertHyperlink)
 .Name = "C:\"  'generates error

> Create a macro with the name InsertHyperlink() and it will then run when you
> right click and select Hyperlink.
[quoted text clipped - 13 lines]
> >
> > Thanks a lot.
Doug Robbins - Word MVP - 20 Dec 2006 21:15 GMT
Hi Greg,

There is something strange here.

While the following code does intercept the command that is run by selecting
Hyperlink from the Right Click Menu, as the Message Box is displayed, when
it is run that way, the ChangeFileOpenDirectory command is ignored.   If
however the macro is run from Tools>Macro>Macros, then the
ChangeFileOpenDirectory command is taken into account:

Sub InsertHyperlink()
Dim BrowseFile As String
MsgBox "OK"
ChangeFileOpenDirectory "c:\Contract Documents\"
With Dialogs(wdDialogFileOpen)
 If .Display <> -1 Then
   Exit Sub
 Else
   BrowseFile = WordBasic.FileNameInfo$(.Name, 1)
 End If
End With
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
   Address:=BrowseFile, TextToDisplay:=Selection.Range.Text
End Sub

It's also a bit flaky in other ways.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Doug,
>
[quoted text clipped - 25 lines]
>> >
>> > Thanks a lot.
Jonathan West - 20 Dec 2006 21:21 GMT
> Hi Greg,
>
[quoted text clipped - 5 lines]
> ignored.   If however the macro is run from Tools>Macro>Macros, then the
> ChangeFileOpenDirectory command is taken into account:

That may well be down to a timing issue. Word VBA occasionaly exhibits this
kind of problem for no immediately obvious reason.

It can often be addressed by putting a couple of DoEvents commands at a
strategic point in the macro, in this case probably immediately below the
ChangeFileOpenDirectory line

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Greg Maxey - 20 Dec 2006 23:59 GMT
Doug,

Worked like a charm here using Word2007 and either method.

Thanks.

> Hi Greg,
>
[quoted text clipped - 60 lines]
> >> >
> >> > Thanks a lot.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.