Help with Excel VBA Save As

Peter Davison

Active Member
Joined
Jun 4, 2020
Messages
433
Office Version
  1. 365
Platform
  1. Windows
I cannot get the following code to do just a simple save as cell value it just comes up with an error on the ActiveWorkbook.SaveAs line. I can't think what I am doing wrong? Any help will be appreciated.
Private Sub CommandButton1_Click()

Dim Path As String
Dim filename1 As String
Path = "C:\"
filename1 = Range("d6").Value
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=Path & filename1 & ".xlsm", FileFormat:=52
Application.DisplayAlerts = True
ActiveWorkbook.Close
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the Board!

What is the exact value in cell D6?
Do you have rights to save things to the root of your C drive?
 
Upvote 0
Welcome to the Board!

What is the exact value in cell D6?
Do you have rights to save things to the root of your C drive?

Welcome
In D6 it is just the word "Davison"
Well spotted I don't have rights to save into C:\ but I can save into a folder within C:\.
I've just tried it and it works.
Thanks so much I've spent hours trying to get my head round that.
I am a newcomer to VBA
Cheers and thanks for your time.
 
Upvote 0
You are welcome.
I am glad it was something simple and we were able to help you get it fixed quickly.
Feel free to come back anytime you need help!
:)
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

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