MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Type mismatch


Posted by orjan on November 05, 2001 10:24 PM

Why does this code generate an error '13' type mismatch at runtime?

Private Sub CommandButton1_Click()
Dim filnavn

filnavn = "m:\regnskap\skifteksport\" + Sheets("Oppsett").Cells("C5").Value + "_" + Sheets("Oppsett").Cells("C6").Value + ".txt"
Workbooks.Open (filnavn)
End Sub

any response will be of great help

orjan


Posted by Paul Akkermans on November 06, 2001 12:12 AM

Dim filnavn
Default type is integer, so Dim filnavn as Variant will help.

Posted by Dank on November 06, 2001 12:16 AM

2 things are wrong with your line:-

You're trying to use the addition (+) symbol to create a string when you have to use ampersand (&).

Secondly, you need to use the Range object of a worksheet, not Cells.

Your statement should look something like this:-


filnavn = "m:\regnskap\skifteksport\" & Sheets("Oppsett").Range("C5").Value & "_" & Sheets("Oppsett").Range("C6").Value & ".txt"

Hope this helps,
Daniel.