I am trying to write a save as button which requests a file name using the standard saveas dialogue, this then performs a series of copy and paste routines then saves the file.
Private Sub SaveResults_Click()
fileSaveName = Application.GetSaveAsFilename(InitialFileName:="query1", _
fileFilter:="Excel Files (*.xls), *.xls")
If fileSaveName <> False Then
Set fs = CreateObject("Scripting.FileSystemObject")
Set fname = fs.GetFile(fileSaveName)
Workbooks.Add.SaveAs Filename:=fname.Name
Windows("web_Reports.xls").Activate
Sheets("Results").Select
ActiveSheet.Range("a:q").Copy
Windows(fname.Name).Activate
Sheets("Sheet1").Select
ActiveSheet.Range("a1").PasteSpecial SkipBlanks:=True
ActiveWorkbook.Save
MsgBox ("File sucessfully saved as :" & Chr(10) & Chr(10) & fileSaveName)
Workbooks(fname.Name).Close SaveChanges:=False
Windows("web_Reports.xls").Activate
End If
End Sub
I am getting an error at the line:
Workbooks.Add.SaveAs Filename:=fname.Name
I am sure I had this working but have changed the code as I also wanted to give the usual options if the file exists.
Also
How do I get the response from the File Exists alert box?
Private Sub SaveResults_Click()
fileSaveName = Application.GetSaveAsFilename(InitialFileName:="query1", _
fileFilter:="Excel Files (*.xls), *.xls")
If fileSaveName <> False Then
Set fs = CreateObject("Scripting.FileSystemObject")
Set fname = fs.GetFile(fileSaveName)
Workbooks.Add.SaveAs Filename:=fname.Name
Windows("web_Reports.xls").Activate
Sheets("Results").Select
ActiveSheet.Range("a:q").Copy
Windows(fname.Name).Activate
Sheets("Sheet1").Select
ActiveSheet.Range("a1").PasteSpecial SkipBlanks:=True
ActiveWorkbook.Save
MsgBox ("File sucessfully saved as :" & Chr(10) & Chr(10) & fileSaveName)
Workbooks(fname.Name).Close SaveChanges:=False
Windows("web_Reports.xls").Activate
End If
End Sub
I am getting an error at the line:
Workbooks.Add.SaveAs Filename:=fname.Name
I am sure I had this working but have changed the code as I also wanted to give the usual options if the file exists.
Also
How do I get the response from the File Exists alert box?