Please Help: Upload a File and save it at a specific location


S

sam

Hi All,

Is there a way to upload a file through excel userform? I am looking to
upload a PDF file throug a userform I have designed.

For eg, Designing a "Browse" button on the form, which on clicking will
display a window where users can select the file they want to submit and
upload it? So once they select a file and click "Submit" button on the
userform, the selected file is saved at a specific location on a shared drive.

Is this possible?

Thanks in Advance
 
Ad

Advertisements

J

Jacob Skaria

Hi Sam

On button click you can try the below two options

Sub Macro1()
Dim varFile As Variant, strDestFolder As String

strDestFolder = "J:\Files"
varFile = Application.GetOpenFilename
If varFile = False Then Exit Sub

'Copy File
FileCopy varFile, strDestFolder & _
Mid(varFile, InStrRev(varFile, Application.PathSeparator))

End Sub

OR if you want to filter this by PDF files you can try the below macro

Sub Macro2()
Dim varFile As Variant, strDestFolder As String

strDestFolder = "J:\Files"

With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Filters.Add "Adobe Acrobat", "*.pdf", 1
.InitialFileName = "C:\"
.Show
If .SelectedItems.Count = 0 Then Exit Sub
varFile = .SelectedItems(1)
End With

'Copy File
FileCopy varFile, strDestFolder & _
Mid(varFile, InStrRev(varFile, Application.PathSeparator))

End Sub



If this post helps click Yes
 
S

sam

Thanks a lot for your help Jacob, Is it possible to desin it such that they
can only upload pdf files and no other format? I want them to see only pdf
files, so they cannot upload files with any other format..

Thanks in advance
 
J

JLGWhiz

It looks to me like that is what Macro2 does. Did you read the post where
it says:

OR if you want to filter this by PDF files you can try the below macro
 
S

sam

Yes, But that one still lets user select "All Files" from Files of type
dropdown in file open window, So once they select "All Files" they are able
to select word, excel files
 
J

JP

If you use the Application.GetOpenFilename method, you can limit the
selection to PDFs only.

--JP
 
Ad

Advertisements

J

JLGWhiz

If you are going to use the dialog box for the user to select from, then you
will not have much choice about how the user manipulates it. But the second
macro limits the choices for most novice users. If it does not have a .pdf
extension, it will not show in the selection window, unless the user knows
to click the file type drop down. Why would they want to do that when the
PDF selections should be right in front of them?

But you can fix that probability with code that if they select a file <> to
..pdf then a message appears that they picked the wrong file type and exit
out of the 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