csilabgirl
Active Member
- Joined
- Aug 14, 2009
- Messages
- 359
Excel 2002
I have some VBA code in a workbook (workbook #1) that runs when the workbook is opened. The code subsequently opens another workbook (workbook #2) and then copies data from it and pastes it into workbook #1. The problem is sometimes the user already has workbook #2 open when they open workbook #1, so they end up getting a debug error. Is there some different code to work around this? Below is my code. Thanks for the help.
Private Sub Workbook_Open()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o> </o>
Dim wbOpen As Workbook<o></o>
<o></o>
Set wbOpen = Workbooks.Open(Filename:="\\Server\Chromosomal Labs\ChromoLIMS\Client List.xls")<o></o>
<o></o>
wbOpen.Sheets("Clients").Columns("D:L").Copy<o></o>
ThisWorkbook.Sheets("Clients").Columns("D:L").PasteSpecial Paste:=xlPasteValues
<o> </o>
wbOpen.Close<o></o>
Sheets("Intro").Select
End Sub<o></o>
I have some VBA code in a workbook (workbook #1) that runs when the workbook is opened. The code subsequently opens another workbook (workbook #2) and then copies data from it and pastes it into workbook #1. The problem is sometimes the user already has workbook #2 open when they open workbook #1, so they end up getting a debug error. Is there some different code to work around this? Below is my code. Thanks for the help.
Private Sub Workbook_Open()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o> </o>
Dim wbOpen As Workbook<o></o>
<o></o>
Set wbOpen = Workbooks.Open(Filename:="\\Server\Chromosomal Labs\ChromoLIMS\Client List.xls")<o></o>
<o></o>
wbOpen.Sheets("Clients").Columns("D:L").Copy<o></o>
ThisWorkbook.Sheets("Clients").Columns("D:L").PasteSpecial Paste:=xlPasteValues
<o> </o>
wbOpen.Close<o></o>
Sheets("Intro").Select
End Sub<o></o>