Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Error handling

Excel 97
I am attempting to move several sheets from one workbook to another for
purposes of emailing only the selected sheets. I am using an array to
select the sheets by name. The code works fine except when a sheet does
not exist. I would like to pop up an error message with the name of the
missing sheet and the option to continue with the sheets that exist. I have
limited experience in this area, and have tried on error goto ErrHandler,
but this does not continue moving the rest of the sheets in the array.
Below I have listed the code. Any help would be greatly appreciated.Thanks
Valerie

Sub ExportSouth()
'Macro Step 3 Export South Sheets
'Opens South Workbook and moves store Sheets to the workbook used for
emailing
'Opens Email to send to District manager

Workbooks.Open FileName:="\\xxx\xxx\xxx\Payroll\South Cover Sheet.xls"
Windows("cover.xls").Activate

Sheets(Array("41 Clark.", "43 Mad.", "44 N.A.", "49 Jeff.")).Move
Befo=Workbooks( _
"South Cover Sheet.xls").Sheets(1)
ActiveWorkbook.Save
Call Email
Sheets(Array("41 Clark.", "43 Mad.", "44 N.A.", "49 Jeff.")).Delete
ActiveWorkbook.Save
ActiveWorkbook.Close
Windows("cover.xls").Activate
Sheets("check List").Range("b9") = "X"

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Error handling

I have solved the one problem by not using an array (seems inefficient, but
works). My question now is how can I get the name of the missing sheet into
the error handler message? Thanks
Valerie
Revised code
Sub ExportSouth()
'Macro Step 3 Export South Sheets
'Opens South Workbook and moves store Sheets to the workbooks
'Opens Email to send to District manager

Workbooks.Open FileName:="\\SBSS\HOME\Valerie\Payroll\South Cover
Sheet.xls"
Windows("cover.xls").Activate

On Error GoTo NoSheet
Sheets("41 Clark.").Move Befo=Workbooks("South Cover
Sheet.xls").Sheets(1)
Windows("cover.xls").Activate
Sheets("43 Mad.").Move Befo=Workbooks("South Cover
Sheet.xls").Sheets(1)
Windows("cover.xls").Activate
Sheets("44 N.A.").Move Befo=Workbooks("South Cover
Sheet.xls").Sheets(1)
Windows("cover.xls").Activate
Sheets("49 Jeff.").Move Befo=Workbooks("South Cover
Sheet.xls").Sheets(1)


ActiveWorkbook.Save
Call Email
Application.DisplayAlerts = False
Sheets("49 Jeff.").Delete
Sheets("44 N.A.").Delete
Sheets("43 Mad.").Delete
Sheets("41 Clark.").Delete



ActiveWorkbook.Save
ActiveWorkbook.Close
Windows("cover.xls").Activate
Sheets("check List").Range("b9") = "X"
Application.DisplayAlerts = True
Exit Sub
NoSheet:
Msg = "The sheet was not available to move or delete, would you like to
continue?"

Ans = MsgBox(Msg, vbYesNo)
If Ans = vbYes Then Resume Next
If Ans = vbNo Then
Windows("South Cover Sheet.xls").Activate
ActiveWindow.Close
End If

End Sub

"V. Roe" wrote in message
...
Excel 97
I am attempting to move several sheets from one workbook to another for
purposes of emailing only the selected sheets. I am using an array to
select the sheets by name. The code works fine except when a sheet does
not exist. I would like to pop up an error message with the name of the
missing sheet and the option to continue with the sheets that exist. I

have
limited experience in this area, and have tried on error goto ErrHandler,
but this does not continue moving the rest of the sheets in the array.
Below I have listed the code. Any help would be greatly appreciated.Thanks
Valerie

Sub ExportSouth()
'Macro Step 3 Export South Sheets
'Opens South Workbook and moves store Sheets to the workbook used for
emailing
'Opens Email to send to District manager

Workbooks.Open FileName:="\\xxx\xxx\xxx\Payroll\South Cover Sheet.xls"
Windows("cover.xls").Activate

Sheets(Array("41 Clark.", "43 Mad.", "44 N.A.", "49 Jeff.")).Move
Befo=Workbooks( _
"South Cover Sheet.xls").Sheets(1)
ActiveWorkbook.Save
Call Email
Sheets(Array("41 Clark.", "43 Mad.", "44 N.A.", "49 Jeff.")).Delete
ActiveWorkbook.Save
ActiveWorkbook.Close
Windows("cover.xls").Activate
Sheets("check List").Range("b9") = "X"

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Error handling

Sub ExportSouth()
'Macro Step 3 Export South Sheets
'Opens South Workbook and moves store Sheets
' to the workbook used for
' emailing
'Opens Email to send to District manager
Dim ans As Variant
Dim varr As Variant
Dim sStr As String
Dim i As Long, j As Long
Dim sh As Worksheet, shts As Sheets
Dim bFirst As Boolean
Dim varr1() As String

Workbooks.Open Filename:="C:\Data5\South Cover Sheet.xls"
Windows("cover.xls").Activate
varr = Array("41 Clark.", "43 Mad.", "44 N.A.", "49 Jeff.")
bFirst = True
sStr = ""
ReDim varr1(LBound(varr) To UBound(varr))
j = LBound(varr)
For i = LBound(varr) To UBound(varr)
Set sh = Nothing
On Error Resume Next
Set sh = Worksheets(varr(i))
On Error GoTo 0
If Not sh Is Nothing Then
sh.Select bFirst
bFirst = False
varr1(j) = sh.Name
j = j + 1
Else
sStr = sStr & varr(i) & vbNewLine
End If
Next
If j = LBound(varr) Then
If varr1(j) = "" Then
MsgBox "No sheets found"
Workbooks("South Cover Sheet.xls").Close _
SaveChanges:=False
Exit Sub
End If
End If
If sStr < "" Then
sStr = "Following sheets are missing:" & vbNewLine & sStr
sStr = sStr & vbNewLine & vbNewLine & "continue?"
ans = MsgBox(sStr, _
vbYesNo + vbCritical + vbQuestion, "Missing Sheets:")
If ans = vbNo Then
' perform cleanup
Workbooks("South Cover Sheet.xls").Close _
SaveChanges:=False
Exit Sub
End If
End If
ActiveWindow.SelectedSheets.Move _
Befo=Workbooks( _
"South Cover Sheet.xls").Sheets(1)
ActiveWorkbook.Save
Call Email
Application.DisplayAlerts = False
Sheets(varr1).Delete
Application.DisplayAlerts = True
ActiveWorkbook.Save
ActiveWorkbook.Close
Windows("cover.xls").Activate
Sheets("check List").Range("b9") = "X"

End Sub

--
Regards,
Tom Ogilvy


"V. Roe" wrote in message
...
I have solved the one problem by not using an array (seems inefficient,

but
works). My question now is how can I get the name of the missing sheet

into
the error handler message? Thanks
Valerie
Revised code
Sub ExportSouth()
'Macro Step 3 Export South Sheets
'Opens South Workbook and moves store Sheets to the workbooks
'Opens Email to send to District manager

Workbooks.Open FileName:="\\SBSS\HOME\Valerie\Payroll\South Cover
Sheet.xls"
Windows("cover.xls").Activate

On Error GoTo NoSheet
Sheets("41 Clark.").Move Befo=Workbooks("South Cover
Sheet.xls").Sheets(1)
Windows("cover.xls").Activate
Sheets("43 Mad.").Move Befo=Workbooks("South Cover
Sheet.xls").Sheets(1)
Windows("cover.xls").Activate
Sheets("44 N.A.").Move Befo=Workbooks("South Cover
Sheet.xls").Sheets(1)
Windows("cover.xls").Activate
Sheets("49 Jeff.").Move Befo=Workbooks("South Cover
Sheet.xls").Sheets(1)


ActiveWorkbook.Save
Call Email
Application.DisplayAlerts = False
Sheets("49 Jeff.").Delete
Sheets("44 N.A.").Delete
Sheets("43 Mad.").Delete
Sheets("41 Clark.").Delete



ActiveWorkbook.Save
ActiveWorkbook.Close
Windows("cover.xls").Activate
Sheets("check List").Range("b9") = "X"
Application.DisplayAlerts = True
Exit Sub
NoSheet:
Msg = "The sheet was not available to move or delete, would you like to
continue?"

Ans = MsgBox(Msg, vbYesNo)
If Ans = vbYes Then Resume Next
If Ans = vbNo Then
Windows("South Cover Sheet.xls").Activate
ActiveWindow.Close
End If

End Sub

"V. Roe" wrote in message
...
Excel 97
I am attempting to move several sheets from one workbook to another for
purposes of emailing only the selected sheets. I am using an array to
select the sheets by name. The code works fine except when a sheet

does
not exist. I would like to pop up an error message with the name of the
missing sheet and the option to continue with the sheets that exist. I

have
limited experience in this area, and have tried on error goto

ErrHandler,
but this does not continue moving the rest of the sheets in the array.
Below I have listed the code. Any help would be greatly

appreciated.Thanks
Valerie

Sub ExportSouth()
'Macro Step 3 Export South Sheets
'Opens South Workbook and moves store Sheets to the workbook used for
emailing
'Opens Email to send to District manager

Workbooks.Open FileName:="\\xxx\xxx\xxx\Payroll\South Cover

Sheet.xls"
Windows("cover.xls").Activate

Sheets(Array("41 Clark.", "43 Mad.", "44 N.A.", "49 Jeff.")).Move
Befo=Workbooks( _
"South Cover Sheet.xls").Sheets(1)
ActiveWorkbook.Save
Call Email
Sheets(Array("41 Clark.", "43 Mad.", "44 N.A.", "49 Jeff.")).Delete
ActiveWorkbook.Save
ActiveWorkbook.Close
Windows("cover.xls").Activate
Sheets("check List").Range("b9") = "X"

End Sub






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
Handling #NUM! error Michel Khennafi Excel Worksheet Functions 1 February 26th 07 08:49 PM
Error Handling Todd Excel Programming 1 February 13th 04 11:29 PM
Error handling Tim C Excel Programming 1 October 7th 03 10:00 PM
Error handling John Pierce Excel Programming 3 October 3rd 03 12:17 PM
Error Handling Bill Lunney Excel Programming 0 August 6th 03 11:56 PM


All times are GMT +1. The time now is 12:24 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"