I am trying to copy an excel sheet from one workbook to another without the user seeing anything but I keep getting the error ‘Copy Method of Worksheet Class failed’. It seems you cant copy one sheet to another workbook unless the workbook is visible?
Thanks for any help.
Hers is the code that fails:
Private Sub CommandButton1_Click()
Dim xlapp As Excel.Application
Dim wkBook As Excel.Workbook
'Connect to Excel
Set xlapp = New Excel.Application
'Set workbook and open workbook in directory
Set wkBook = xlapp.Workbooks.Open(sFileName, xlUpdateLinksNever, ReadOnly:=False)
ThisWorkbook.Sheets("Logistics").Copy Before:=wkBook.Sheets(1)
wkBook.Close True
xlapp.Quit
Set xlapp = Nothing
End Sub
Another way to achieve what you want.