ThisIsMachiel
New Member
- Joined
- Mar 26, 2018
- Messages
- 2
Hi,
I created a macro, and when I run it i getting the runtime error 13 Type mismatch. I'm relatively new, so hopefully it will be an Easy solution. The idea of this part of the macro is to let the user open another excel file and copy the testsheet to the active workbook. The runtime error happens on the bold red line.
Sub CreateNewWorksheet()
'Variables
Dim ORMWorksheetLocation As Variant
Dim Thiswb As Workbook
Set Thiswb = ActiveWorkbook
Dim Testsheet1 As Worksheet
Set Testsheet1 = ActiveSheet
'Rename worksheet
Testsheet1.Name = "TestSheet1"
'Choose excel file to open
ORMWorksheetLocation = Application.GetOpenFilename(FileFIlter:="Excel Files,*.xl*;*.xm*")
If ORMWorksheetLocation <> False Then
Workbooks.Open Filename:=ORMWorksheetLocation
Else
MsgBox ("You have not selected a File")
End If
'Copy ORM Testsheet
ActiveSheet.Copy After:=Workbooks(Thiswb).Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "ORM testsheet HY1"
ActiveWorkbook.Close
End Sub
As far as I could find the error happens because of the Workbooks(Thiswb), but because i defined the variable Thiswb as a workbook, I'm not sure why
Any help is welcome. This is written in excel 2010
Thanks!
I created a macro, and when I run it i getting the runtime error 13 Type mismatch. I'm relatively new, so hopefully it will be an Easy solution. The idea of this part of the macro is to let the user open another excel file and copy the testsheet to the active workbook. The runtime error happens on the bold red line.
Sub CreateNewWorksheet()
'Variables
Dim ORMWorksheetLocation As Variant
Dim Thiswb As Workbook
Set Thiswb = ActiveWorkbook
Dim Testsheet1 As Worksheet
Set Testsheet1 = ActiveSheet
'Rename worksheet
Testsheet1.Name = "TestSheet1"
'Choose excel file to open
ORMWorksheetLocation = Application.GetOpenFilename(FileFIlter:="Excel Files,*.xl*;*.xm*")
If ORMWorksheetLocation <> False Then
Workbooks.Open Filename:=ORMWorksheetLocation
Else
MsgBox ("You have not selected a File")
End If
'Copy ORM Testsheet
ActiveSheet.Copy After:=Workbooks(Thiswb).Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "ORM testsheet HY1"
ActiveWorkbook.Close
End Sub
As far as I could find the error happens because of the Workbooks(Thiswb), but because i defined the variable Thiswb as a workbook, I'm not sure why
Any help is welcome. This is written in excel 2010
Thanks!