Save to same path

2Took

Board Regular
Joined
Jun 13, 2022
Messages
203
Office Version
  1. 365
Platform
  1. Windows
Getting this error on below code:

2022-08-08_16h42_57.png


VBA Code:
Private Sub CommandButton1_Click()

Dim Path As String

With CreateObject("Scripting.FileSystemObject")
ActiveSheet.Name = "Data ~ " & Format(Now(), "MM.dd.yy")
End With

MyName = ActiveSheet.Name & " - " & Format(Now(), "hh.mm.ss am/pm")
'MyName = ActiveSheet.Range("B2").Value

Const csPath As String = ThisWorkbook.Path & "\" 'Same path as this file location.

Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:=csPath & MyName & ".xlsm"
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi 2Took,

You can't assign something that's dynamic (changeable) to a constant variable. You should use the Path variable that's been created.

Regards,

Robert
 
Upvote 0
Solution

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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