Reputation: 119
Any idea why I'm getting a type mismatch error here? The cursor highlights the second last "&" in the filename string at the bottom of this code. Something to do with the variable dt which is meant to be a date. Any ideas?
Code:
Sub daily_report_data()
Dim strpath1 As String
Dim strpath2 As String
Dim wb As Workbook
Dim wb2 As Variant
Dim ws As Worksheet
Dim nm As String
Dim dt() As Date
strpath1 = "\\ironhide\[folder name]\[folder name]\[folder name]\[folder name]\"
strpath2 = "c:\Users\[user.name]\desktop\data files\"
Workbooks.Open Filename:=strpath1 & "[file name].xlsx", ReadOnly:=True
Set wb = Workbooks("[file name]")
Set ws = Workbooks("[file name]").Sheets("data")
nm = ws.Name
dt = Date
Workbooks.Add
DoEvents
ActiveWorkbook.SaveAs strpath2 & nm & "_" & dt & ".xlsx"
Set wb2 = Workbooks(nm & dt & ".xlsx")
Upvotes: 0
Views: 1254
Reputation: 2477
Try using something like this:
Dim FileNPath As String
Dim strDate As String
Dim dt As Date
strDate = Format(dt, "ddmmyyyy")
FileNPath = strpath2 & nm & "_" & strDate & ".xlsx"
ActiveWorkbook.SaveAs fileName:=FileNPath
Upvotes: 0
Reputation: 9244
You have declared:
Dim dt() As Date
That's an array. You can't use the "&" string concatenation operator on an array. Just remove the ().
Upvotes: 1