#1   Report Post  
Steve
 
Posts: n/a
Default Help amending code

Hi

I have the following code set to a commandbutton:

Workbooks.Open Filename:= _
"\\Statistics\Year 05-06\September.xls"

However, if the sheet is already open in the background, I get an error
message. What can I add to this code so that, if the sheet is already
open, it just switches over to it?

TIA

Steve

  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default


On Error Resume Next
Set oWb = Workbooks("September.xls")
If oWb Is Nothing Then
Set oWb = Workbooks.Open Filename:= _
"\\Statistics\Year 05-06\September.xls"
Endf If
On Error Goto 0
oWb.Activate


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Steve" wrote in message
oups.com...
Hi

I have the following code set to a commandbutton:

Workbooks.Open Filename:= _
"\\Statistics\Year 05-06\September.xls"

However, if the sheet is already open in the background, I get an error
message. What can I add to this code so that, if the sheet is already
open, it just switches over to it?

TIA

Steve



  #3   Report Post  
Steve
 
Posts: n/a
Default

Thanks Bob.

For some reason I keep getting the red error line; the "Filename" part
seems to be the problem...?

Steve

  #4   Report Post  
Bob Phillips
 
Posts: n/a
Default

Sorry Steve, missed the brackets

On Error Resume Next
Set oWb = Workbooks("September.xls")
If oWb Is Nothing Then
Set oWb = Workbooks.Open(Filename:= _
"\\Statistics\Year 05-06\September.xls")
End If
On Error GoTo 0
oWb.Activate


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Steve" wrote in message
oups.com...
Thanks Bob.

For some reason I keep getting the red error line; the "Filename" part
seems to be the problem...?

Steve



  #5   Report Post  
Steve
 
Posts: n/a
Default

That did it. Thanks a lot, Bob.

Best,

Steve

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
Change case...help please Terry Excel Worksheet Functions 14 October 2nd 05 12:29 PM
Macro for changing text to Proper Case JPriest Excel Worksheet Functions 3 August 8th 05 09:31 PM
Using other workbooks.. DavidMunday Excel Worksheet Functions 2 July 1st 05 07:35 AM
Make Change Case in Excel a format rather than formula Kevin Excel Worksheet Functions 1 March 18th 05 08:53 PM
Help with Amending this Code Please [email protected] Excel Worksheet Functions 4 February 1st 05 07:04 PM


All times are GMT +1. The time now is 03:50 PM.

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"