Trying to "scroll" thru the worksheets in a wb and move them to a workbook and email taht work book. This code works for only the first sheet in the book then it hangs on:
ActiveWorkbook.Worksheets(I).Select
ActiveWorkbook.Worksheets(I).Select
Code:
Sub EmailSheets()
Dim Worksheet
Dim RSID As String
Dim WS_Count As Integer
Dim I As Integer
' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop.
For I = 1 To WS_Count
ActiveWorkbook.Worksheets(I).Select '--- HANGS UP ON THIS LINE ---
RSID = ActiveSheet.Name
Dim OL As Object
Dim EmailItem As Object
Dim wb As Workbook
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set wb = ActiveWorkbook
wb.Save
Sheets(RSID).Select
Sheets(RSID).Move
ActiveWorkbook.SaveAs Filename:= _
"[URL="file://\\Ac35dfsps02p\s3_data$\FLR"]\\Ac35dfsps02p\s3_data$\FLR[/URL] CDR\" & RSID & ".xls", FileFormat:=xlExcel8 _
, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
With EmailItem
.Subject = "Unassigned Leads Report for " & RSID
.Body = " Unassigned Leads Report for " & RSID & " (" & RSID & ".xlsm) attached!" & vbCrLf & _
" " & vbCrLf & _
" "
.To = RSID & "@SOMEWHERE.COM"
' .Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add wb.FullName ' change this name for each rsid
UserForm1.Label1.Caption = "Emailing your report to" & RSID
UserForm1.Repaint
.Send
End With
Set wb = Nothing
Set OL = Nothing
Set EmailItem = Nothing
Next I
End Sub