PDA

View Full Version : Check the active workbook



Sir Babydum GBE
01-23-2008, 10:01 AM
I have a macro recorded in MyWorkbook.xls.

The macro reorganises columns and picks up information from whatever workbook is the active one, copies it, then pastes it to MyWorbook.

How can I get the macro to first check that MyWorkbook.xls isn't the active one - and if it is, put up a message: "Please activate the source workbook and re-run the macro" - and then exit the code? Whereas - if it's not the active book - it can carry on as normal.

Thanks

BD

Jan Karel Pieterse
01-23-2008, 11:15 AM
If ActiveWorkbook Is ThisWorkbook Then
'We're looking at the workbook with the code
Else
'Another workbook is active
End If

Sir Babydum GBE
01-23-2008, 11:46 AM
If ActiveWorkbook Is ThisWorkbook Then
'We're looking at the workbook with the code
Else
'Another workbook is active
End IfThat's great thanks Jan!