How to prompt user to fill in folder name

K

kurt

Hello,

I need to create a macro in Word that prompts the user for the name of a
folder on a particular drive, then based on that user input, prompts the user
a second time for the name of a subfolder. For example, after I activate the
macro, I want to see a dialog box which prompts me for the folder name (maybe
2 or 3 characters.) I fill that in, then click OK, and am prompted again for
a subfolder name. I fill that in, click OK, and am brought to the folder
where I can save a file, etc.

I know how to create the dialog box. I just need code which will prompt a
user for the folder names. I'd rather the code not be an "if" statement with
either one folder or the next or the next in the elseif statements. The code
needs to open ANY folder based on user input of the folder's name.

THANKS FOR HELPING!
Kurt
 
A

Astrid

Hi Kurt,

Any reason why you don't use the built-in dialogs?

Sub SelectAFolder()
Dim sFolder As String

With Dialogs(wdDialogFileSaveAs)
If .Display Then
'User pressed ok
sFolder = .Name
'Get the name and extract the path
sFolder = WordBasic.filenameinfo(.Name, 5)
MsgBox sFolder
Else
'user closed the dialog without input
End If
End With

End Sub

If you want to predefine a startingfolder, change it a bit to:

Dim sFolder As String
Const csStartFolder As String = "D:\"

With Dialogs(wdDialogFileSaveAs)
.Name = csStartFolder
If .Display Then
'User pressed ok
sFolder = .Name
'Get the name and extract the path
sFolder = WordBasic.filenameinfo(.Name, 5)
MsgBox sFolder
Else
'user closed the dialog without input
End If
End With

Hope this helps,
kind regards,
Astrid
 

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