Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
GregR
 
Posts: n/a
Default Activate a workbook from a selection

I usually have a number of workbooks open at the same time. In a macro I
need to move one sheet from the active workbook to another workbook and then
reactivate the original workbook. The original workbook that is open is one
of several that begins with RF________________.xls. How do I reactivate the
original RF_____________.xls. There is only one workbook with the
RF___________.xls name open at a time. TIA

Greg


  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

How about something like:

Option Explicit
Sub testme()

Dim CurWkbk As Workbook
Dim OtherWkbk As Workbook
Dim FoundIt As Boolean
Dim SheetNameToCopy As String

SheetNameToCopy = "Sheet1"

Set CurWkbk = ActiveWorkbook
If LCase(Left(CurWkbk.Name, 2)) = "rf" Then
MsgBox "You're in the RF workbook!"
Exit Sub
End If

FoundIt = False
For Each OtherWkbk In Application.Workbooks
If LCase(Left(OtherWkbk.Name, 2)) = "rf" Then
FoundIt = True
Exit For
End If
Next OtherWkbk

If FoundIt = True Then
CurWkbk.Worksheets(SheetNameToCopy).Copy _
befo=OtherWkbk.Worksheets(1)
CurWkbk.Activate
Else
MsgBox "no RF workbook is open!"
End If

End Sub



GregR wrote:

I usually have a number of workbooks open at the same time. In a macro I
need to move one sheet from the active workbook to another workbook and then
reactivate the original workbook. The original workbook that is open is one
of several that begins with RF________________.xls. How do I reactivate the
original RF_____________.xls. There is only one workbook with the
RF___________.xls name open at a time. TIA

Greg


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOW DO I SUM TWO CELLS FROM ONE WORKBOOK TO ANOTHER WORKBOOK? Bill O'Neal Excel Worksheet Functions 8 August 14th 09 11:36 PM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Unprotect Workbook Kent Excel Discussion (Misc queries) 1 February 4th 05 01:07 AM
make hidden window or workbook visible without specify the name mango Excel Worksheet Functions 1 December 30th 04 03:05 PM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM


All times are GMT +1. The time now is 09:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"