PDA

View Full Version : Solved: SaveAs Macro Code



jammer6_9
04-22-2007, 01:04 PM
How can I write a code that will save as the workbook with newworkbook and in a certain location

Sub SaveAs()
ActiveWorkbook.SaveAs ("New")
End Sub

lucas
04-22-2007, 02:02 PM
Here's a start...I used the macro recorder to get this:
Sub Macro1()
ChDir "C:\Documents and Settings\main\Desktop\temp"
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\Dan&Stacy\Desktop\temp\Book1.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End Sub

YellowLabPro
04-22-2007, 02:10 PM
There are special settings in this code, I use it for a text file and I assign it w/ a timestamp. All can be cut out if you don't need, I am just giving as an example.



Dim sPath as String
Dim wb As Workbook
Dim ws?? As Worksheet
Set wb = Workbooks("yourworkbookname.xls")
Set wsEC = Worksheets("sheetname")
wb.Save
ws??.Activate
sPath = "C:\DocsandSetting\Desktop\My Documents\Excel\"

With ws??
.SaveAs Filename:=sPath & "yourworkbookname " & _
Format(Now, "m-dd-yy") & " @ " & Format(Now, "h_mm_ss am/pm") & ".txt", _
FileFormat:=xlTextMSDOS
End With

jammer6_9
04-22-2007, 02:24 PM
Gotcha :cloud9: