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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,575
Messages
6,125,616
Members
449,238
Latest member
wcbyers

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