PDA

View Full Version : activating a window in the taskbar



philfer
01-22-2011, 07:58 AM
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

mdmackillop
01-22-2011, 02:18 PM
Try this way

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