VBA workbook open debug

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-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Dim wbOpen As Workbook<o:p></o:p>
<o:p></o:p>
Set wbOpen = Workbooks.Open(Filename:="\\Server\Chromosomal Labs\ChromoLIMS\Client List.xls")<o:p></o:p>
<o:p></o:p>
wbOpen.Sheets("Clients").Columns("D:L").Copy<o:p></o:p>
ThisWorkbook.Sheets("Clients").Columns("D:L").PasteSpecial Paste:=xlPasteValues
<o:p> </o:p>
wbOpen.Close<o:p></o:p>
Sheets("Intro").Select
End Sub<o:p></o:p>
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
VoG,

I am not sure how it worked once and now does not, but I am getting that same compile error and its highlighting the ISOpen part again. Any ideas?

Thanks
 
Upvote 0
Try my code, its something that I use in one of my workbooks and havent had a problem with it yet.
 
Upvote 0
Bjurny,

I will give yours a try and let you know.

VoG,
I just realized that in the copy I was testing I had that public code in the module and then also the new this workbook code and it worked. In the final copy I only pasted in the new this workbook code and that it the one that is not working, so I guess I need both codes.
 
Upvote 0
Bjurney,

I was reading your code and realize it is set to close workbook #2 (so that is can open it again), but I dont want workbook 2 to close on the user. Thank you for the code thought. It might have an application for something down the road, just not this project.
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top