+ Reply to Thread
Results 1 to 5 of 5

Help amending code

  1. #1
    Steve
    Guest

    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. #2
    Bob Phillips
    Guest

    Re: Help amending code


    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" <[email protected]> wrote in message
    news:[email protected]...
    > 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. #3
    Steve
    Guest

    Re: Help amending code

    Thanks Bob.

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

    Steve


  4. #4
    Bob Phillips
    Guest

    Re: Help amending code

    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" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks Bob.
    >
    > For some reason I keep getting the red error line; the "Filename" part
    > seems to be the problem...?
    >
    > Steve
    >




  5. #5
    Steve
    Guest

    Re: Help amending code

    That did it. Thanks a lot, Bob.

    Best,

    Steve


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1