The code below is not executing correctly due to the fact that I believe I am not toggling between the workbook where I am executing the code (wbCodeBook), and where I am copying the gPA worksheet (wbResults). Any ideas where I am going wrong?
Thanks in advance....Code:For i = 1 To 50 If FileOrDirExists("X:\2010 BUDGET\" & stateHold(i)) Then With Application.FileSearch .NewSearch .LookIn = "X:\2010 BUDGET\" & stateHold(i) .FileType = msoFileTypeExcelWorkbooks .Filename = "*.xls" If .Execute > 0 Then 'Workbooks in folder For lCount = 1 To .FoundFiles.Count ' Loop through all. Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0) wbResults.Activate If IsNumeric(Mid(wbResults.Name, 3, 4)) Then For Each wks In Worksheets Select Case wks.Name Case gPA wks.Unprotect wks.Copy wbCodeBook.Activate wbCodeBook.Sheets.Add.Name = wbResults.Name & " - GPA" Sheets(wbResults.Name & " - GPA").Select Selection.Paste End Select Next wks End If wbResults.Activate wbResults.Close SaveChanges:=True Next lCount End If End With End If Next i
scm24
you could copy the sheet to the other workbook with
then rename sheetCode:Sheets(1).Copy Before:=Workbooks.(wbCodeBook).Sheets(1)
hope it helpsCode:Workbooks.(wbCodeBook).Sheets("Sheet1").Name = "pike"
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
JBeaucaires Excel Files
VBA for smarties - snb
Here's some code I found.
I Don't know if this is what you want, but you can try this.
Insert this code into each workbook that you want to toggle between.
Create a button at the top of a sheet within each book. Assign the macro placed into each book to the button. This will allow you to toggle.
HTH'sCode:Sub NextBk() Dim NumBooks As Integer, n As Integer Dim ThisBook As Integer, FirstBk As Integer NumBooks = Workbooks.Count If Workbooks(1).Name = "YourOpenWorkbookName.xls" Then FirstBk = 2 Else FirstBk = 1 End If For n = FirstBk To NumBooks If Workbooks(n).Name = ActiveWorkbook.Name Then ThisBook = n Next If ThisBook < NumBooks Then ' move to the next books Workbooks(ThisBook + 1).Activate End If If ThisBook = NumBooks And NumBooks > FirstBk Then ' move back to first book Workbooks(FirstBk).Activate End If End Sub
BDB
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks