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 / November 2005

Tip: Looking for answers? Try searching our database.

Browse for a specific path

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tjtjjtjt - 15 Nov 2005 17:55 GMT
Is there a way to capture a directory location for use later in a macro?

I'm looking for the ability to create a button similar to the MODIFY...
button on the File Locations tab of the Options dialog box. I will be the
only person who uses this code.

Basically, I want to create a UserForm that I will use to Save my documents
to 3 separate locations simultaneously.
I have a macro that does this already, but I can't change the locations for
different documents. I want to make it more flexible by giving myself the
option to override the default save locations.

Ultimately, I hope to use a naming convention to have documents with
specific prefixes save to specific directories, but I've got a lot of work
and learning to do to get there.

Thanks,
Signature

tj

Jay Freedman - 15 Nov 2005 18:46 GMT
There are a number of ways to do a directory browser. Don't spend a lot of
time reinventing the wheel, fire, and beer. :-) Visit
http://ccrp.mvps.org/controls/ccrpbdsvr6.htm and download the CCRP
BrowseDialog Server.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Is there a way to capture a directory location for use later in a
> macro?
[quoted text clipped - 14 lines]
>
> Thanks,
tjtjjtjt - 15 Nov 2005 19:07 GMT
Thanks, I'll check it out.

Signature

tj

> There are a number of ways to do a directory browser. Don't spend a lot of
> time reinventing the wheel, fire, and beer. :-) Visit
[quoted text clipped - 19 lines]
> >
> > Thanks,
tjtjjtjt - 15 Nov 2005 20:05 GMT
I suspect I am missing something obvious...
How do I call this in my word procedure and have the file path I browse to
copy into a textbox?

Signature

tj

> There are a number of ways to do a directory browser. Don't spend a lot of
> time reinventing the wheel, fire, and beer. :-) Visit
[quoted text clipped - 19 lines]
> >
> > Thanks,
Jay Freedman - 15 Nov 2005 21:53 GMT
First download the zip and extract it into any folder of your choice. The
programs in the \demo subfolder, especially BDSvr6Demo.exe, show some of the
fancy things it can do.

To get just the basic functionality working on a userform:

- In the VBA editor, go to Tools > References, click the Browse button, and
select ccrpbds6.dll wherever you unzipped it. Then go down the alphabetized
part of the list and check the box next to CCRP BrowseDialog Server. That
will enable both the context-sensitive F1 help in the editor and the
"IntelliSense" popups.

- Put a textbox and a Browse button in your userform, and put some code like
this behind it:

Private Sub cmdBrowse_Click()
  Dim BrowseDlg As BrowseDialog
  Set BrowseDlg = New BrowseDialog
  With BrowseDlg
     .RootFolder = "C:\"
     .SelectedFolder = "C:\Documents and Settings"
     If .Browse Then
        TextBox1.Text = .SelectedFolder
     End If
  End With
End Sub

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> I suspect I am missing something obvious...
> How do I call this in my word procedure and have the file path I
[quoted text clipped - 28 lines]
>>>
>>> Thanks,
tjtjjtjt - 15 Nov 2005 23:34 GMT
Thanks. After I unzipped it (before my follow-up post to you), I could only
get the BDSvr6Demo.exe to run. The Help Files, etc. just gave me errors.
I'll play with it on my home computer and find out what the restrictions are
at work.
Signature

tj

> First download the zip and extract it into any folder of your choice. The
> programs in the \demo subfolder, especially BDSvr6Demo.exe, show some of the
[quoted text clipped - 55 lines]
> >>>
> >>> Thanks,
Doug Robbins - Word MVP - 15 Nov 2005 20:27 GMT
I use the following to load a textbox (txtFldrPath) on a userform with the
folder selected by the user when they click on a Browse button
(btnBrowseforFolder):

Private Sub btnBrowseforFolder_Click()
Dim SH As Shell32.Shell
Dim Fldr As Shell32.Folder
Set SH = New Shell32.Shell
Set Fldr = SH.BrowseForFolder(0, "Select folder in which to save the files",
&H400)
If Not Fldr Is Nothing Then
   txtFldrPath.Text = Fldr.Items.Item.Path & "\"
End If
Set Fldr = Nothing
End Sub

It is necessary to have a reference set to the Microsoft Shell Controls and
Automation object library.

Or you can use:

Dim MyPath As String

'let user select a path
With Dialogs(wdDialogCopyFile)
   If .Display() <> -1 Then Exit Sub
   MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
   MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
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

> Is there a way to capture a directory location for use later in a macro?
>
[quoted text clipped - 15 lines]
>
> Thanks,
tjtjjtjt - 15 Nov 2005 21:11 GMT
Thanks, Doug. I'll give it a shot.

Signature

tj

> I use the following to load a textbox (txtFldrPath) on a userform with the
> folder selected by the user when they click on a Browse button
[quoted text clipped - 51 lines]
> >
> > Thanks,
tjtjjtjt - 15 Nov 2005 21:50 GMT
I have a simple version of this working. Thanks, again - you saved me quite a
headache.

Signature

tj

> I use the following to load a textbox (txtFldrPath) on a userform with the
> folder selected by the user when they click on a Browse button
[quoted text clipped - 51 lines]
> >
> > Thanks,
Jonathan West - 16 Nov 2005 12:05 GMT
If you are using Word 2002 (Office XP) or Word 2003, then you can use the
FileDialog object to give you a folder picker dialog

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

> Is there a way to capture a directory location for use later in a macro?
>
[quoted text clipped - 15 lines]
>
> Thanks,
 
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.