VBA Code issues - Cannot get file to save as using cell contents

ilaughatgas

New Member
Joined
Aug 17, 2016
Messages
3
Hi guys, I'm pretty new to VBA. I know there are some similar threads on here which have similar issues, I've worked my way through them and I'm still at a loss as to why my code won't work. I'm trying to create a button which will save the workbook to a certain location using the contents of three cells, the code I'm using is:

Private Sub CommandButton1_Click()
Dim Path As String
Dim Filename1 As String
Dim Filename2 As String
Dim Filename3 As String
Path = "I:\Ashford\Departments\_Private\CI Team\_Ted Barton\Other\Mezz floor paperwork project\Saved files"
Filename1 = Range("D3")
Filename2 = Range("G3")
Filename3 = Range("J3")
ThisWorkbook.SaveAs Filename:=Path & Filename1 & "-" & Filename2 & "-" & Filename3 & "-" & ".xlsm", FileFormat:=52




End Sub

When I click the command button the error I get reads "Run-time error '1004': Method 'SaveAs' of object '_Workbook' failed. I click debug and the debugger highlights the part of the code I've put in red above

I think it has something to do with the file extension names, I've tried playing around but to no avail. Your help on this would be greatly appreciated.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Path = "I:\Ashford\Departments\_Private\CI Team\_Ted Barton\Other\Mezz floor paperwork project\Saved files\"
 
Upvote 0
That's got it, thank you so much for your prompt help. It's greatly appreciated. Apologies for my inexperience with these things.

Thanks again, take care
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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