Remember file name selected

A

art

Hello:

I have the following code to get a file name:

Sub GetFileName()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = Application.DefaultFilePath & "\"
.Title = "Please select a location for the PDF orders"
.Show
If .SelectedItems.Count = 0 Then
MsgBox "Canceled"
Else
myfilename = .SelectedItems(1)
End If
End With
End Sub

I want use MyFileName in another module, but the filename does not save the
selected file? how can I make MyfileName "remember" and save the file the
user selected?

Thanks.
 
N

Neptune Dinosaur

Assuming I understand your code and your intent correctly, an alternative to
storing it in a worksheet would be to declare the variable as Public. That
way it would be static (i.e. it would stay "alive" outside that Sub) and
would be availabe to other Subs in the project.
 
R

Robin Clay

Or start your routine with
Sub GetFileName(myFileName)
instead of
Sub GetFileName()

and then:-

Sub CallingRoutine
Blah - blah - blah
GetFileName(myFileName)
Open myFileName for Input as #1
Blah - blah - blah
End Sub
 

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