Find Selected Area's Workbook Name

  • Hello Everydody,


    This is my first post, so I have to tell you I'm very happy I found you.


    I have 5 (same time) opened workbooks.


    I ask user (via VBA's inputbox) to select an area in worksheet "ws1" of workbook "wbx" (where 2<=x<=5) while the Active.Workbook is "wb1".


    the code I use is


    Code
    dim myRange as Range
    Set myRange = Application.InputBox(Prompt:="Please select ...", _
    Title:="Area Selection", Type:=8)


    this works fine, then I can use


    Code
    myRange.Worksheet.Name


    to get the name of the worksheet where the users selected an area, but


    I don't know how to get the name of the Workbook in which the users made it's selection?


    Thanks in advance

    Christos Lepesiotis

  • Re: Find Selected Area's Workbook Name


    Hello!


    Not sure if Im on the right track here, but since you cant change the workbook when the macro is active the workbook you make the selection from will always be the active one. From there you should be able to get the name with:

    Code
    ActiveWorkbook.Name


    Kind regards
    /Henrik

  • Re: Find Selected Area's Workbook Name


    Thanks guys but I have allready tried

    Code
    ActiveWorkbook.Name


    and it brings me wb1, while I expect a name like wb2, wb3, wb4, or wb5.


    I need to use a command or a method in conjunction with variable

    Code
    myRange

    Christos Lepesiotis

  • Re: Find Selected Area's Workbook Name


    YES Andy
    this works perfectly

    Code
    ' workbook
    Msgbox myRange.parent.parent.name


    In fact, "parent" will offer great functionality to my future codes.


    :congrats: :congrats: :congrats:


    Thank you all.


    Do you think I should publish this small utility I make when I finish it?


    Would it be ok to publish it in this thread, or should I start a new one?

    Christos Lepesiotis

  • Re: Find Selected Area's Workbook Name


    Quote

    Do you think I should publish this small utility I make when I finish it?


    Would it be ok to publish it in this thread, or should I start a new one?


    I think that would be a great and in keeping with the idea of sharing.
    As to where to post I think it would be better suited in either the Showcase or Open Source forums.

    [h4]Cheers
    Andy
    [/h4]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!