View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Terry Pinnell[_4_] Terry Pinnell[_4_] is offline
external usenet poster
 
Posts: 192
Default Activate a workbook?

Claus Busch wrote:

Hi Terry,

Am Sat, 04 Mar 2017 10:05:24 +0000 schrieb Terry Pinnell:

I added a line
Workbooks("Walk Index.xlsm").Work.Activate
at the end of my copying macro, to ensure that the workbook 'Walk Index'
was in focus:


try:
Workbooks("Walk Index.xlsm").Activate


Regards
Claus B.


Hi Claus,

Thanks, that works fine in the macro I posted. I actually made a minor
edit to correct my mistake; it's the SOURCE workbook I want to activate,
not the destination 'Walk Index.xlsm'

To make the selected workbook more obvious (the windows look very
similar in Windows 10) I then tried adding another line:

Workbooks("TEST track sheet copying.xlsm").Activate
Sheets("TEMP").Range(“A1”).Select
But that failed.

Also, on advice over in the Excel Forum, I've changed it to a neater
version like this:

Sub CopyTrackSheetToWalkIndex_FromTMS()

With ThisWorkbook
With Sheets("Track Data")
.Range("B5").Copy Destination:=Workbooks("Walk
Index.xlsm").Sheets("TEMP").Range("C2")
.Range("B10").Copy Destination:=Workbooks("Walk
Index.xlsm").Sheets("TEMP").Range("J2")
etc
etc
..Range("B22").Copy Destination:=Workbooks("Walk
Index.xlsm").Sheets("TEMP").Range("AM2")
.Range("B23").Copy Destination:=Workbooks("Walk
Index.xlsm").Sheets("TEMP").Range("AQ2")
.Range("B24").Copy Destination:=Workbooks("Walk
Index.xlsm").Sheets("TEMP").Range("AR2")
End With
End With
Workbooks("TEST track sheet copying.xlsm").Activate
End Sub

In this version the last line causes an error: Run-time error
'9':Subscript out of range

Terry, East Grinstead, UK