activate workbook

K

Kevin

My VBA for Excel code (in workbook WB1) generates some data, writes it to a
worksheet (WS1), creates a new workbook (WB2), moves the worksheet (WS1) to
WB2 and then activates WB1. But the taskbar appears to indicate that WB2 is
active when WB1 is actually the active workbook. I can't see that any
problem except for this appearance. Any thoughts? What would I do to make
it appear that WB1 is active?

I've uploaded a screen print.
http://www.kevinjperez.com-a.googlepages.com/ExcelOut.JPG

Thanks.


Kevin
 
K

Kevin

The code:

Sub MoveWorksheets()
Dim TestSheet As Worksheet, NewBook As Workbook
MasterSheet$ = "Plant_Mon"
MasterFullName$ = MasterWorkbook.FullName
MasterFileName$ = GetFilename(MasterFullName$)
MasterPath$ = GetPath(MasterFullName$)
Set NewBook = Workbooks.Add
NewBook.SaveAs Filename:=strNewFullName
MasterWorkbook.Activate
For Each sh In ActiveWorkbook.Worksheets
ThisSheetName$ = sh.Name
For LoopAP% = 1 To 18
SheetNameJ$ = Sheets("SheetConfig").Cells(LoopAP%, 1)
If ThisSheetName$ = SheetNameJ$ Then GoTo LineLabelAQ
Next LoopAP%
Sheets(ThisSheetName$).Move After:=Workbooks(strNewFileName).Sheets(1)
Workbooks(strNewFileName).Worksheets(ThisSheetName$).Activate
For intSheetNum% = 1 To 3
strSheetNum$ = CStr(intSheetNum%)
SheetNameK$ = "Sheet" & strSheetNum$
On Error Resume Next
Set TestSheet = Worksheets(SheetNameK$)
If Not TestSheet Is Nothing Then
Sheets(SheetNameK$).Delete
End If
On Error GoTo 0
Next intSheetNum%
MasterWorkbook.Activate
LineLabelAQ:
Next sh
Workbooks(strNewFileName).Save
MasterWorkbook.Activate
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top