checking if workbook is open before accessing
Hi,
I've developed a Userform which adds data to several workbooks depending on the choice made in combobox. The macro is as follows: Dim appExcel As Excel.Application Dim lastrow As Excel.Range Dim Choice as Workbook Set appExcel = Application appExcel.DisplayAlerts = False appExcel.ScreenUpdating = False consultant = cbConsultant.Text If consultant = "Persons name" then Set Choice = appExcel.Workbooks.Open(FileName:="C:\test1.xls") ElseIf consultant = "Person2" Then Set etc..... end if Set lastrow = Choice.Worksheets("sheet1").Range("a65536").End(xl Up) etc...... This works fine but my problem is that if another user is in test.xls the program stops and I get a file save as dialog. I would like to build some form of error message so that the user is told who is currently using test1.xls and once the other user has exited test1.xls the macro then continues. I have noticed the on Error and Resume functions but I'm not sure how to implement them. Many thanks David |
All times are GMT +1. The time now is 04:51 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com