siCIVIC1986
Registered User.
- Local time
- Today, 02:18
- Joined
- Feb 22, 2010
- Messages
- 12
Hi all
I am currently trying to copy a tab from one workbook ("List.xls") to another ("IGEN_QC.xls") but I keep getting an error which I hoped somebody would be able to take a quick glance at my code to see if there is anything immediately wrong with it.
Error:
I keep getting an error that says
Thanks in advance
I am currently trying to copy a tab from one workbook ("List.xls") to another ("IGEN_QC.xls") but I keep getting an error which I hoped somebody would be able to take a quick glance at my code to see if there is anything immediately wrong with it.
Error:
I keep getting an error that says
Method 'Copy' of object '_Worksheet' failed
Code:
Sub copydata()
Dim wkbSource As Workbook
Dim wkbDest As Workbook
Dim shttocopy As Worksheet
Dim wbname As String
On Error GoTo ErrHandl
' check if the file is open
ret = Isworkbookopen("List.xls")
If ret = False Then
' open file
Set wkbSource = Workbooks.Open("List.xls")
Else
' Just make it active
Set wkbSource = Workbooks("List.xls")
End If
' check if the file is open
ret = Isworkbookopen("IGEN_QC.xls")
If ret = False Then
' open file
Set wkbDest = Workbooks.Open("IGEN_QC.xls")
Else
' Just make it active
Set wkbDest = Workbooks("IGEN_QC.xls")
End If
' perform copy
Set shttocopy = wkbSource.Sheets("List")
'shttocopy.Copy wkbDest.Sheets(2)
shttocopy.Copy wkbDest.Sheets
ErrHandl:
MsgBox Err.Description
Err.Clear
End Sub
Function Isworkbookopen(filename As String)
Dim ff As Long, ErrNo As Long
Dim wkb As Workbook
Dim nam As String
wbname = filename
On Error Resume Next
ff = FreeFile()
Open filename For Input Lock Read As #ff
Close ff
ErrNo = Err
On Error GoTo 0
Select Case ErrNo
Case 0: Isworkbookopen = False
Case 70: Isworkbookopen = True
Case Else: Error ErrNo
End Select
End Function
Thanks in advance