robertsmyth100
Board Regular
- Joined
- Sep 25, 2006
- Messages
- 94
Hi there,
I have a simple peice of VB code that when a button is pressed opens another workbook say 'workbook2', performs a paste from workbook1 into workbook2 and then closes workbook2. If another user has workbook2 already open then there is an error and the code stops working. Is there a way to make the code handle the error and show a message box saying 'try again later' in workbook1? My VB skills are basic indeed but the code I have so far is...
Sub copy_workbook2()
Sheets("1").Select
Rows("19:50").Select
Selection.Copy
On Error GoTo Handler
Workbooks.Open Filename:="\Workbook2"
Sheets("1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
Handler:
MsgBox ("File in use, try again")
Workbooks.Open Filename:="\workbook2"
End Sub
This code doesn't work as intended and I am not sure I am going about this the right way. Any help would be appreciated...
I have a simple peice of VB code that when a button is pressed opens another workbook say 'workbook2', performs a paste from workbook1 into workbook2 and then closes workbook2. If another user has workbook2 already open then there is an error and the code stops working. Is there a way to make the code handle the error and show a message box saying 'try again later' in workbook1? My VB skills are basic indeed but the code I have so far is...
Sub copy_workbook2()
Sheets("1").Select
Rows("19:50").Select
Selection.Copy
On Error GoTo Handler
Workbooks.Open Filename:="\Workbook2"
Sheets("1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWorkbook.Save
ActiveWorkbook.Close
Handler:
MsgBox ("File in use, try again")
Workbooks.Open Filename:="\workbook2"
End Sub
This code doesn't work as intended and I am not sure I am going about this the right way. Any help would be appreciated...