Ask the working path to the user

S

Steff

Hi,

I would like to pop up a form when the document open and asking user
the working folder by browsing until the folder. Store the folder path
into a public variable.

Thanks

Stephane Vial
 
M

macropod

Hi Steff,

The following sub & function shows how you can browse for a folder:

Sub Browse()
MyFolder GetFolder(Title:="Find a Folder", RootFolder:=&H11)
End Sub

Function GetFolder(Optional Title As String, Optional RootFolder As Variant) As String
On Error Resume Next
GetFolder = CreateObject("Shell.Application").BrowseForFolder(0, Title, 0, RootFolder).Items.Item.Path
End Function

The selected folder name is stored in the variable 'MyFolder'.

To have the sub run automatically, you could rename it 'Document_Open'. For other options, look under 'Auto Macros' in Word's help
file. You might also want to add some code to check that a folder has actually been selected.

Cheers
 
S

Steff

Hi Steff,

The following sub & function shows how you can browse for a folder:

Sub Browse()
MyFolder GetFolder(Title:="Find a Folder", RootFolder:=&H11)
End Sub

Function GetFolder(Optional Title As String, Optional RootFolder As Variant) As String
On Error Resume Next
GetFolder = CreateObject("Shell.Application").BrowseForFolder(0, Title,0, RootFolder).Items.Item.Path
End Function

The selected folder name is stored in the variable 'MyFolder'.

To have the sub run automatically, you could rename it 'Document_Open'. For other options, look under 'Auto Macros' in Word's help
file. You might also want to add some code to check that a folder has actually been selected.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------



Steff said:
I would like to pop up a form when the document open and asking user
the working folder by browsing until the folder. Store the folder path
into a public variable.

Stephane Vial- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

Hello,

When a tried to execute the code, a have the following error message

Compile error : Sub or Function Not Define

I put the sub in a modules and the function in a class modules !!

Thanks for your help

Stephane
 
R

Russ

Steff,
In case you didn't notice it subroutine Browse() was missing a couple of
things, a declaration and an equal character for an assignment for the
MyFolder variable. When added, everything works great for me. :

Sub Browse()
Dim MyFolder As String
MyFolder = GetFolder(Title:="Find a Folder", RootFolder:=&H11)
End Sub
Hi Steff,

The following sub & function shows how you can browse for a folder:

Sub Browse()
MyFolder GetFolder(Title:="Find a Folder", RootFolder:=&H11)
End Sub

Function GetFolder(Optional Title As String, Optional RootFolder As Variant)
As String
On Error Resume Next
GetFolder = CreateObject("Shell.Application").BrowseForFolder(0, Title, 0,
RootFolder).Items.Item.Path
End Function

The selected folder name is stored in the variable 'MyFolder'.

To have the sub run automatically, you could rename it 'Document_Open'. For
other options, look under 'Auto Macros' in Word's help
file. You might also want to add some code to check that a folder has
actually been selected.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------



Steff said:
I would like to pop up a form when the document open and asking user
the working folder by browsing until the folder. Store the folder path
into a public variable.

Stephane Vial- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

Hello,

When a tried to execute the code, a have the following error message

Compile error : Sub or Function Not Define

I put the sub in a modules and the function in a class modules !!

Thanks for your help

Stephane
 
S

Steff

Steff,
In case you didn't notice it subroutine Browse() was missing a couple of
things, a declaration and an equal character for an assignment for the
MyFolder variable. When added, everything works great for me. :

Sub Browse()
Dim MyFolder As String
MyFolder = GetFolder(Title:="Find a Folder", RootFolder:=&H11)
End Sub




Hi Steff,
The following sub & function shows how you can browse for a folder:
Sub Browse()
MyFolder GetFolder(Title:="Find a Folder", RootFolder:=&H11)
End Sub
Function GetFolder(Optional Title As String, Optional RootFolder As Variant)
As String
On Error Resume Next
GetFolder = CreateObject("Shell.Application").BrowseForFolder(0, Title, 0,
RootFolder).Items.Item.Path
End Function
The selected folder name is stored in the variable 'MyFolder'.
To have the sub run automatically, you could rename it 'Document_Open'.. For
other options, look under 'Auto Macros' in Word's help
file. You might also want to add some code to check that a folder has
actually been selected.
Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------
messageHi,
I would like to pop up a form when the document open and asking user
the working folder by browsing until the folder. Store the folder path
into a public variable.
Thanks
Stephane Vial- Masquer le texte des messages précédents -
- Afficher le texte des messages précédents -

When a tried to execute the code, a have the following error message
Compile error : Sub or Function Not Define
I put the sub in a modules and the function in a class modules !!
Thanks for your help

--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -

Thanks a lot......Now it works fine for me too !!

Thanks

Stéphane Vial
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top