Type mismatch at saveas filename statement

ChanL

Board Regular
Joined
Apr 8, 2021
Messages
65
Office Version
  1. 2019
Platform
  1. Windows
Hit type mismatch error at the saveas filename row , and i believe its because there is a mixture of string and integer for the variable in the filename. Can anyone advice on this?

VBA Code:
Dim prd as string, dept as string, yrs as integer

prd=ThisWorkbook.Sheets("Main").Range("I10").value
dept=ThisWorkbook.Sheets(Main").Range("I11").value
yrs=ThisWorkbook.Sheets(Main").Range("I12").value

ChDir ThisWorkbook.Sheets("Main").Range("I13").value
:Activeworkbook.saveas filename := "EKYC" + prd + "_" + yrs + "_" + "dept" + ".xlsm"
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
The concatenation operator is an ampersand & not the plus + symbol.

VBA Code:
Dim prd as string, dept as string, yrs as integer

With ThisWorkbook.Sheets("Main")
prd = .Range("I10").value
dept = .Range("I11").value
yrs = .Range("I12").value

ChDir .Range("I13").value
End With
Activeworkbook.saveas filename := "EKYC" & prd & "_" & yrs & "_" & "dept" & ".xlsm"
 
Upvote 0
Solution
Try change: "EKYC" + prd + "_" + yrs + "_" + "dept" + ".xlsm"

to: "EKYC" & prd & "_" & yrs & "_" & "dept" & ".xlsm"
 
Upvote 0
Glad to help and thanks for the feedback.
Please could you mark this post as solved.
Thank you, Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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