Help in vba

  • Thread starter Thread starter DareDevil
  • Start date Start date
D

DareDevil

Hi everyboby..
I am new to this group, I hope u people can help me out..
I have a vba application...
when i click a button i should be able to duplicate a csv file with a
new name in the desired location of user ..
Thanks and regards
Hoping a valuable reply
 
Do you need the user to search for the csv file to duplicate or will he be
saving a copy of the workbook he's in? If you need to search for the file,
you'll need to prompt the user with something like this:

Sub copyCSVfile()

Dim sSourceCSVfile As String
Dim sNewCSVfile As String
Dim wbCSV As Workbook

' Get source file
Do
sSourceCSVfile = Application.GetOpenFilename(FileFilter:="CSV Files
(*.csv), _ *.csv")
Loop While (sSourceCSVfile = "False")

' Open the file
Set wbCSV = Workbooks.Open(Filename:=sSourceCSVfile, ReadOnly:=True)

' Get new name
Do
sNewCSVfile = Application.GetSaveAsFilename(InitialFileName:=Left
_(wbCSV.Name, Len(wbCSV.Name) - 4) & " copy", FileFilter:="CSV Files (*.csv),
_ *.csv")
Loop While (sNewCSVfile = "False")

' Save a copy and close
wbCSV.SaveAs Filename:=sNewCSVfile
wbCSV.Close SaveChanges:=False
Set wbCSV = Nothing

End Sub


HTH,
Matthew Pfluger
 

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

Back
Top