Consulting

Results 1 to 2 of 2

Thread: activating a window in the taskbar

  1. #1
    VBAX Tutor
    Joined
    Nov 2007
    Posts
    291
    Location

    activating a window in the taskbar

    Hi, I am writing a macro that opens another workbook, grabs some data and then closes that workbook without saving any changes However, when that workbook is closed the excel workbook 'clicked' in the taskbar (on XP) is another workbook that is open rather than the one that was originally running the macro. I used :- windows(ThisWorkbook.Name).activate ThisWorkbook.Worksheets("MySheet").Activate ThisWorkbook.Worksheets("MySheet").select and all combinations of the above and whilst the Workbook does become the active workbook (when I type it types onto the sheet in the workbook it is another workbook that is 'clicked' in the taskbar and I have to physically click on my workbook to 'click' it on the taskbar so it is selected Hope that isnt too confusing!!! Can anyone help Cheers P

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try this way

    [VBA]Option Explicit

    Sub GetData()
    Dim WB As Workbook
    Dim ThsBk As Workbook

    Set ThsBk = ActiveWorkbook
    Set WB = Workbooks.Open("C:\AAA\Test.xls")

    ThsBk.Sheets(1).Cells(2, 2) = WB.Sheets(1).Cells(1, 1)
    WB.Close False
    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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