Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: selecting a workbook

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    75
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Here is my query. Is there a way to right in code that would tell excel to activate or select the workbook that the macro is located in.

    example: I have a macro that opens another workbook and copies several cells from that workbook. Then I need to paste those copied cells into a the workbook that the macro was written in or associated with. I know I could do this buy using the file name of the
    destination sheet, but that changes regularly. but the same macro will always be associated with a given workbook no matter what the workbook name. If anyone out here has any idea if this is possible I would apreciate the help.

  2. #2
    Board Regular
    Join Date
    Feb 2002
    Location
    Stockton, California
    Posts
    281
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Yes, in your macro, before you open any other workbooks, just set a variable.

    Dim currentworkbook as string

    currentworkbook=activeworkbook.name

    put that in before you open any other workbooks, then later you can refer to the original workbook as "currentworkbook"


  3. #3
    Board Regular
    Join Date
    Mar 2002
    Posts
    75
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks very much, I have been look for that little tid bit for a while..

  4. #4
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    As an Alternative to RobFo0s help....

    In your code Use the ThisWorkbook Object qualifyer to reference the workbook that the code is currently from.

    Eg instead of

    Workbook(whatever).dosomething

    use

    Thisworkbook.dosomething


    Kind Regards,
    Ivan F Moala From the City of Sails

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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