Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default HELP: saving a file with specific name

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HELP: saving a file with specific name


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 taking
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 & NewFileName


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=149299

  #3   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default HELP: saving a file with specific name

Thanks Joel,

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

Thanks again

"joel" wrote:


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 taking
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 & NewFileName


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=149299

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving file to specific directory sungen99[_75_] Excel Programming 1 February 22nd 06 02:01 PM
VBA for saving a file to a specific location TimT Excel Programming 6 July 7th 05 08:50 PM
Saving a file using a specific name in a cell SU Excel Worksheet Functions 4 February 25th 05 12:30 AM
Saving file to a specific folder richkim2000 Excel Discussion (Misc queries) 1 January 25th 05 11:11 PM
Disabling Saveas and saving file with a specific name only Hari[_3_] Excel Programming 3 June 14th 04 08:34 PM


All times are GMT +1. The time now is 03:32 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"