Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Atlanta, GA
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Activate another window (2000)

    I will have 2 files open, one will always have the same name, the other could have any name. I want to be able to activate or deactivate both files. I know the command to activate the known window e.g. Windows("Book4.xls").activate but I don't know how to activate the second open window when I'm not sure of the file name (assume there will be only two files open at any time).

    I have the same problem when I attempt to copy a sheet to an unknown file name (again assuming only 2 files will be open). I know the command for a known file e.g. ActiveSheet.Copy before:=Workbooks("Book1.xls").Sheets("Spreadsheet ").
    Is there some way to copy a sheet to an unknown named file?

    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Activate another window (2000)

    Do you open this other workbook in code, or is it opened by the user before the macro is run?

  3. #3
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Atlanta, GA
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Activate another window (2000)

    The user opens the file with the unknown name which already contains the macro that opens a file with a known name.

    Explanation: The macro is intended to open on a template which many files will be based on. So when the user opens the template he/she will save under a different name. The next time the file is opened, it will contain the same macro which opens the known file name.

  4. #4
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Activate another window (2000)

    This
    Sheets("Sheet1").Copy Before:=Sheets(2)
    Will copy in existing workbook

    This
    Sheets("Sheet1").Copy
    Will copy the sheet into a NEW workbook (and create it)

    This
    Sheets("Sheet1").Copy Before:=Workbooks("Book2").Sheets(1)
    Will copy into an existing workbook

    Steve

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Activate another window (2000)

    ThisWorkbook represents the workbook in which the code is running. So you can use code like

    ThisWorkbook.Activate

    and

    ActiveSheet.Copy Before:=ThisWorkbook.Sheets("Spreadsheet")

    If you need the name, you can use ThisWorkbook.Name.

Posting Permissions

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