saveas VBA

MR3

Board Regular
Joined
Jun 10, 2008
Messages
175
Code:
Sub saveas()
fileSaveName = Application.GetSaveAsFilename( _
    fileFilter:="Text Files (*.txt), *.txt")
If fileSaveName <> False Then
    MsgBox "Save as " & fileSaveName
End If
End Sub [\code]

when i run this code it seems to work but when i go to the directory where the new file is supposed to be save the file does not exist.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
You have to save the file! Maybe

Code:
Sub saveMeas()
filesavename = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.txt), *.txt")
If filesavename <> False Then
MsgBox "Save as " & filesavename
ActiveWorkbook.saveas Filename:=filesavename, FileFormat:=xlTextWindows
End If
End Sub
 
Upvote 0
which argument would date/timestamp go in for the saveas in the file name?
 
Upvote 0
Do you mean that you want to append the date and time to the filename that GetSaveAsFileName returns?
 
Upvote 0
Yep that is correct so that every time i run the macro, a new file name with new timestamp will be generated. This will ensure organization of hundreds of files.
 
Upvote 0
Try like this

Code:
Sub SaveMeAs()
Dim FileSaveName As Variant
FileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.txt), *.txt")
If FileSaveName <> False Then
    FileSaveName = Left(FileSaveName, Len(FileSaveName) - 3) & Format(Now, "mm-dd-yyyy hh:mm:ss") & "txt"
    MsgBox "Save as " & FileSaveName
    ActiveWorkbook.saveas Filename:=FileSaveName, FileFormat:=xlTextWindows
End If
End Sub
 
Upvote 0
Correction

Code:
Sub SaveMeAs()
Dim FileSaveName As Variant
FileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.txt), *.txt")
If FileSaveName <> False Then
    FileSaveName = Left(FileSaveName, Len(FileSaveName) - 4) & Format(Now, "mm-dd-yyyy hh:mm:ss") & ".txt"
    MsgBox "Save as " & FileSaveName
    ActiveWorkbook.saveas Filename:=FileSaveName, FileFormat:=xlTextWindows
End If
End Sub
 
Upvote 0


I keep getting this error.... and it highlights the line ActiveWorkbooks

ActiveWorkbook.SaveAs Filename:=FileSaveName, FileFormat:=xlTextWindows
 
Upvote 0
You could also try

Rich (BB code):
Sub SaveMeAs()
Dim FileSaveName As Variant
FileSaveName = Application.GetSaveAsFilename( _
fileFilter:="Text Files (*.txt), *.txt")
If FileSaveName <> False Then
    FileSaveName = Left(FileSaveName, Len(FileSaveName) - 4) & Format(Now, "mm-dd-yyyy hh:mm:ss") & ".txt"
    MsgBox "Save as " & FileSaveName
    ActiveWorkbook.SaveAs Filename:=FileSaveName, FileFormat:=xlText
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top