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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
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,215,744
Messages
6,126,621
Members
449,322
Latest member
Ricardo Souza

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