• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Browse a file and save to a default folder

Hi,


Can anyone help me with a simple vba code which i can use to browse a file and once when selected the file should be saved in a default folder.


Regards,

Ramnath
 
Here you go...


Code:
Sub SaveFiles()

Dim Retval As Variant


    With Application

Retval = .GetSaveAsFilename(, fileFilter:="Text Files (*.txt), *.txt, Excel 97-2003 (*.xls),*.xls, Excel 2007 (*.xlsx),*.xlsx")

If Retval <> False Then

ThisWorkbook.SaveAs Retval

End If

End With

End Sub


~Vijay
 
Hi Vijay,


Thanks a million for your immediate reply.


I have to apologize that I have not mentioned that it is a PDF file.


Brief process is as below:


A Form with Upload button will be given to some 10 users who have to browse their scanned pdfs and the same should be saved in my default network folder.


Also I have to generate some unique file number which is location specific.


Location A will have A0402201100001 (Location, Date & Serial No) and should continue

Location B will have B0402201100001.....


I know i am asking for a bit too much. But if you can help it would be great help.


Thanks a lot.


Regards,

Ramnath
 
Hi Vijay,


I browsed a sample code from online and changed 2-3 lines to fit my requirement. This is working fine now.


Hearty thanks for your kind help. I am posting this for others benefit.


-------------------------------------------------

Sub commandbutton1_click()

Dim fs As Object

Dim oldPath As String, newPath As String

oldPath = Application.GetOpenFileName("PDF Files,*.pdf,All Files,*.*", 1, "Open File", , False)

'oldPath = "C:Documents and Settingsramnath.divakaranDesktop" 'Folder file is located in

newPath = "C:Documents and Settingsramnath.divakaranMy DocumentsCMOCMO_Maker_Folder" 'Folder to copy file to

Set fs = CreateObject("Scripting.FileSystemObject")

fs.CopyFile oldPath, newPath & "" & Format(Now(), "yyyymmddhhmmss") & ".PDF"

Set fs = Nothing

End Sub

--------------------------------------------------------------


Regards,

Ramnath
 
Back
Top