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.
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.