Guest_imported
New member
- Jan 1, 1970
- 0
When I use the following code, an error appears (runtime-error 1004: Method of class failed)
Sub insertData()
dim workbookname as string
DlgAnswer = Application.Dialogs(xlDialogOpen).Show
workbookname=activeworkbook.name
...
workbooks(workbookname).close
end sub
The purpose is to open a second workbook, retrieve data from it, and then close this workbook.
However, this code only works if only 1 sheet is open. From the moment that 2 sheets are open (even if one sheet is hidden), the code produces the error 1004.
What am I doing wrong?
Sub insertData()
dim workbookname as string
DlgAnswer = Application.Dialogs(xlDialogOpen).Show
workbookname=activeworkbook.name
...
workbooks(workbookname).close
end sub
The purpose is to open a second workbook, retrieve data from it, and then close this workbook.
However, this code only works if only 1 sheet is open. From the moment that 2 sheets are open (even if one sheet is hidden), the code produces the error 1004.
What am I doing wrong?