+ Reply to Thread
Results 1 to 6 of 6

Activating / Closing workbook using part name and a wild character

  1. #1
    sharman
    Guest

    Activating / Closing workbook using part name and a wild character

    Hi,

    Is it possible to activate/close an open workbook by a macro by using just
    the part name alongwith with a wild character? Like if the workbook name is
    "NewBook_6_10" and I want to activate/close it by just using "New*". I
    tried using it but I get an error message. Thanks in advance.



  2. #2
    Tom Ogilvy
    Guest

    Re: Activating / Closing workbook using part name and a wild character

    Dim bk as Workbook
    for each bk in application.Workbooks
    if bk.Name like "New*" then
    bk.Activate
    exit for
    end if
    Next

    --
    Regards,
    Tom Ogilvy


    "sharman" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > Is it possible to activate/close an open workbook by a macro by using

    just
    > the part name alongwith with a wild character? Like if the workbook name

    is
    > "NewBook_6_10" and I want to activate/close it by just using "New*". I
    > tried using it but I get an error message. Thanks in advance.
    >
    >




  3. #3
    sharman
    Guest

    Re: Activating / Closing workbook using part name and a wild chara

    Hi Tom,

    Thanks for the quick response. Using your code, I can activate and close the
    workbook using just the part name. Can I also kill it by just using the part
    name?

    "Tom Ogilvy" wrote:

    > Dim bk as Workbook
    > for each bk in application.Workbooks
    > if bk.Name like "New*" then
    > bk.Activate
    > exit for
    > end if
    > Next
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "sharman" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi,
    > >
    > > Is it possible to activate/close an open workbook by a macro by using

    > just
    > > the part name alongwith with a wild character? Like if the workbook name

    > is
    > > "NewBook_6_10" and I want to activate/close it by just using "New*". I
    > > tried using it but I get an error message. Thanks in advance.
    > >
    > >

    >
    >
    >


  4. #4
    Norman Jones
    Guest

    Re: Activating / Closing workbook using part name and a wild character

    Hi Sharman,

    Try something like:


    Sub TestMe()
    Dim WB As Workbook

    For Each WB In Application.Workbooks
    If LCase(Left(WB.Name, 3)) = "new" Then
    WB.Close (False)
    End If
    Next
    End Sub



    ---
    Regards,
    Norman



    "sharman" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > Is it possible to activate/close an open workbook by a macro by using
    > just
    > the part name alongwith with a wild character? Like if the workbook name
    > is
    > "NewBook_6_10" and I want to activate/close it by just using "New*". I
    > tried using it but I get an error message. Thanks in advance.
    >
    >




  5. #5
    Tom Ogilvy
    Guest

    Re: Activating / Closing workbook using part name and a wild chara

    No. But once you have identified it you have the whole name.

    Dim bk as Workbook
    for each bk in application.Workbooks
    if bk.Name like "New*" then
    bk.Activate
    sName = bk.FullName
    bk.Close SaveChanges:=False
    kill sName
    exit for
    end if
    Next

    Using Kill with a wildcard kills everything that matches.

    --
    Regards,
    Tom Ogilvy

    "sharman" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Tom,
    >
    > Thanks for the quick response. Using your code, I can activate and close

    the
    > workbook using just the part name. Can I also kill it by just using the

    part
    > name?
    >
    > "Tom Ogilvy" wrote:
    >
    > > Dim bk as Workbook
    > > for each bk in application.Workbooks
    > > if bk.Name like "New*" then
    > > bk.Activate
    > > exit for
    > > end if
    > > Next
    > >
    > > --
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "sharman" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Hi,
    > > >
    > > > Is it possible to activate/close an open workbook by a macro by using

    > > just
    > > > the part name alongwith with a wild character? Like if the workbook

    name
    > > is
    > > > "NewBook_6_10" and I want to activate/close it by just using "New*".

    I
    > > > tried using it but I get an error message. Thanks in advance.
    > > >
    > > >

    > >
    > >
    > >




  6. #6
    sharman
    Guest

    Re: Activating / Closing workbook using part name and a wild chara

    Thanks a lot.

    "Norman Jones" wrote:

    > Hi Sharman,
    >
    > Try something like:
    >
    >
    > Sub TestMe()
    > Dim WB As Workbook
    >
    > For Each WB In Application.Workbooks
    > If LCase(Left(WB.Name, 3)) = "new" Then
    > WB.Close (False)
    > End If
    > Next
    > End Sub
    >
    >
    >
    > ---
    > Regards,
    > Norman
    >
    >
    >
    > "sharman" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi,
    > >
    > > Is it possible to activate/close an open workbook by a macro by using
    > > just
    > > the part name alongwith with a wild character? Like if the workbook name
    > > is
    > > "NewBook_6_10" and I want to activate/close it by just using "New*". I
    > > tried using it but I get an error message. Thanks in advance.
    > >
    > >

    >
    >
    >


+ 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