Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem opening a file


Hi everyone, i have a piece of basic code that calls a workbook

Workbooks.Open Filename:="\\server1\files\amy\Activity.xls"

This works perfectly, until I navigate away from Activity.xls back t
the main sheet workbook called Main.xls.
What happens is that when I am back in Main.xls and run the above cod
to go back to Activity.xls it create a run-time error 1004 as the fil
is already open.

Does anyone know if I can add some code to see if the file is open, an
it it is activate it, otherwise open the file afresh?

Thanks for your help.

Amy x

--
AmyTaylo
-----------------------------------------------------------------------
AmyTaylor's Profile: http://www.excelforum.com/member.php...fo&userid=2097
View this thread: http://www.excelforum.com/showthread.php?threadid=39605

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem opening a file


Good morning AmyTaylor

The code below will test if a named file is open:

Sub CheckFile()
On Error Resume Next
Set a = Workbooks("\\server1\files\amy\Activity.xls")
If Err = 0 Then
Windows("\\server1\files\amy\Activity.xls").Activa te
End If
End Sub

If the file is already open then it will be made the active sheet. If
not, nothing happens.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=396055

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem opening a file


Thanks Dominic, but this isnt exactly what I want. If the file isnt ope
then I want it to open it, otherwise it just activates the sheet as i
will be already open.

Thanks for your help.
Amx

--
AmyTaylo
-----------------------------------------------------------------------
AmyTaylor's Profile: http://www.excelforum.com/member.php...fo&userid=2097
View this thread: http://www.excelforum.com/showthread.php?threadid=39605

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem opening a file


Hi Amy

I know, I know. I seem to have a real problem reading the last fe
words of a post. Please excuse my silliness and try this instead.

Sub CheckFile()
On Error Resume Next
Set a = Workbooks("\\server1\files\amy\Activity.xls")
If Err = 0 Then
Windows("\\server1\files\amy\Activity.xls").Activa te
Exit Sub
End If
Workbooks.Open Filename:="\\server1\files\amy\Activity.xls"
End Sub

Is that any better?

HTH

Dominic

--
dominic
-----------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...fo&userid=1893
View this thread: http://www.excelforum.com/showthread.php?threadid=39605

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem opening a file


Dominic, thank you again ! x

But.....it always opens the file afresh, and doesnt just activate it i
the file is already open - this really isnt a problem but if a user i
accessing it across the network on a slow line it could cause
problem.
Any ideas ?
Thanks
Amy x

--
AmyTaylo
-----------------------------------------------------------------------
AmyTaylor's Profile: http://www.excelforum.com/member.php...fo&userid=2097
View this thread: http://www.excelforum.com/showthread.php?threadid=39605

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
problem opening file Markb Excel Discussion (Misc queries) 7 January 3rd 10 08:03 PM
Problem opening a file Dave Excel Discussion (Misc queries) 3 September 28th 07 06:37 PM
Problem Opening Excel File Nad Excel Discussion (Misc queries) 1 August 25th 07 02:55 PM
opening file problem please help Steve Goodrich Excel Discussion (Misc queries) 2 March 1st 05 10:40 PM
My Add-in causes problem with opening a file twice masayoshi hayashi Excel Programming 1 December 30th 03 06:55 AM


All times are GMT +1. The time now is 09:51 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"