Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default checking if workbook is open before accessing

Hi

Dim appExcel As Excel.Application
Dim lastrow As Excel.Range
Dim Choice As Workbook

On Error GoTo ErrorStop

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......
Exit Sub
ErrorStop:

MsgBox "Your Info"


--
JP




"David Goodall" wrote in message
...
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RETRIEVE DATA FROM ANOTHER WORKBOOK BY CHECKING ON WORKBOOK DATE Joe Excel Worksheet Functions 13 May 27th 08 01:52 AM
Using a Wildcard (*) in formula accessing sheets in workbook. pwk Excel Worksheet Functions 1 February 4th 07 06:47 PM
Prevent Username Accessing Workbook Martin Whitehead Setting up and Configuration of Excel 1 April 2nd 06 12:44 PM
VBA Excel Checking whether an XL file is already open elsewhere Kamal Hussain Excel Programming 2 August 19th 03 02:03 PM
Accessing/Clearing range in hidden workbook DarrenW Excel Programming 2 July 17th 03 04:00 AM


All times are GMT +1. The time now is 08:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"