VBA SaveFile

Stromma

Board Regular
Joined
Feb 8, 2004
Messages
240
Hi All

I have created a backup that makes a copy and save it to a disc. How can i at the same time make a copy that's always are stored in the same path where the user keep the original workbook and name it with ex: Sheets("Test").Range("A1") + Sheets("Test").Range("C3")?

Roger
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Here is some code for you to look at:

Sub SaveAsCode()
Dim sFileName As String, sFilePath As String
Dim oFileScript As Object

sFileName = Sheets("Test").Range("A1") & Sheets("Test").Range("C3") & ".xls"
sFilePath = ThisWorkbook.Path & "\"

Set oFileScript = CreateObject("Scripting.FileSystemObject")
If oFileScript.fileexists(sFilePath & sFileName) Then
MsgBox "A file by the name " & sFileName & " already exists in " & sFilePath _
& vbCrLf & "Choose another name"
Application.Dialogs(xlDialogSaveAs).Show (sFileName)
Else
ThisWorkbook.SaveAs (sFilePath & sFileName)
End If

Set oFileScript = Nothing
End Sub


I think this does what you want, but I also included a check that a file doesn't already exist with the name you specify. If it does the above code will prompt the user for another name.
 
Upvote 0
Hi, Roger,

I think you need this
Code:
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & yourfilename

regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,842
Members
449,471
Latest member
lachbee

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