HELP: saving a file with specific name

S

sam

Hi All,

I have this piece of code that on click displays a dialog window where we
can select a pdf file and once we select the file it saves the file at the
specified location.

What I want: I want it to be saved by a specific name. Rite now its just
saving at the specified location with the original name which I want to
change to one of the form fields name.

Here is my code for that:

Private Sub Browse_Click()

Dim varFile As Variant, strDestFolder As String, FName As String

srDestFolder = "C:\My Documents\"
FName = "LP -" & Me.StuName.Value
With Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Adobe Acrobat", "*.pdf", 1
.Show
If .SelectedItems.Count = 0 Then Exit Sub
varFile = .SelectedItems(1)
End With

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

MsgBox ("Your file has been uploaded")

End Sub

Thanks in advance.
 
J

joel

this is the line that is performing the copy

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

Varfile : Is the complete path name of the file to be copied

strDestFolder : Is the destination Folder


This line below removes the filename from path name
Mid(varFile, InStrRev(varFile, Application.PathSeparator))


for example
from
c:\temp\abc.pdf
to
abc.pdf

the code is looking for the last backslash using INSTRREV and takin
everything after the last back slash

So you would need to do this

from
FileCopy varFile, strDestFolder & _
Mid(varFile, InStrRev(varFile, Application.PathSeparator))


to
NewfileName = "abc.pdf"
FileCopy varFile, strDestFolder & NewFileNam
 
S

sam

Thanks Joel,

I will try that now. I am also working on the access thing that you
previously helped me with.

Thanks again
 

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