N
nrage21
The macro below runs tru a set of commandbuttons... as these are presse
a range of cells is checked, if everything is ok, then it copies th
range, opens and pastes the range in workbook2.
When the user clicks on another commandbutton excell asks me if I wan
to reopen Workbook2. I want to say No (because workbook2 is alread
open at this point), then that's when I am presented with erro
'1004'.
"Method 'Open' of Object 'Workbooks' failed.
I want to bypass error '1004' and continue with the paste operation i
workboo2.
My code...
Private Sub CmBLI1_1000_1_Click()
'10:00
If Application.WorksheetFunction.CountA(Range("E7:G7")) < _
Range("E7:G7").Cells.Count Then
MsgBox "Complete ALL Fields"
Else
Range("C7:J7").Copy
Set rng = ActiveSheet.Range("C7:J7")
Workbooks.Open _
("C:\My Documents\Workbook2.xls")
Set rng1 = ActiveSheet.Range("A13004").End(xlUp).Offset(1, 0)
rng.Copy Destination:=rng1
End If
End Sub
and some code I found at another site for trapping errors, but I don
know where to place this, if it works.
'Module is already in progress
On Error GoTo ErrHandler
'Tell VBA to use your trapping routine
'Module continues then
Selection.Value = 123
Exit Sub 'You must exit the sub or the
'Error Handler is invoked
'everytime you come to the end of the macro
ErrHandler:
Select Case Err
'Err is already defined in Excel to hold the
'numeric code for errors
Case 91
MsgBox "There is no active cell"
Case 1000
MsgBox "Cannot assign a value to the selection."
Case 1004
MsgBox Err & " " & Error(Err) & Chr(13) & Chr(13) _
& "The method you specified cannot be used on the object."
Case 1005
MsgBox "The worksheet is protected."
Case Else
MsgBox Error(Err) & err.number & err.description
End Select
End Sub
Any help is greatly appreacited!
TIA
- Larry -
VBA Amateu
a range of cells is checked, if everything is ok, then it copies th
range, opens and pastes the range in workbook2.
When the user clicks on another commandbutton excell asks me if I wan
to reopen Workbook2. I want to say No (because workbook2 is alread
open at this point), then that's when I am presented with erro
'1004'.
"Method 'Open' of Object 'Workbooks' failed.
I want to bypass error '1004' and continue with the paste operation i
workboo2.
My code...
Private Sub CmBLI1_1000_1_Click()
'10:00
If Application.WorksheetFunction.CountA(Range("E7:G7")) < _
Range("E7:G7").Cells.Count Then
MsgBox "Complete ALL Fields"
Else
Range("C7:J7").Copy
Set rng = ActiveSheet.Range("C7:J7")
Workbooks.Open _
("C:\My Documents\Workbook2.xls")
Set rng1 = ActiveSheet.Range("A13004").End(xlUp).Offset(1, 0)
rng.Copy Destination:=rng1
End If
End Sub
and some code I found at another site for trapping errors, but I don
know where to place this, if it works.
'Module is already in progress
On Error GoTo ErrHandler
'Tell VBA to use your trapping routine
'Module continues then
Selection.Value = 123
Exit Sub 'You must exit the sub or the
'Error Handler is invoked
'everytime you come to the end of the macro
ErrHandler:
Select Case Err
'Err is already defined in Excel to hold the
'numeric code for errors
Case 91
MsgBox "There is no active cell"
Case 1000
MsgBox "Cannot assign a value to the selection."
Case 1004
MsgBox Err & " " & Error(Err) & Chr(13) & Chr(13) _
& "The method you specified cannot be used on the object."
Case 1005
MsgBox "The worksheet is protected."
Case Else
MsgBox Error(Err) & err.number & err.description
End Select
End Sub
Any help is greatly appreacited!
TIA
- Larry -
VBA Amateu