![]() |
Why Wont This Work? VBA Help Needed!
Why Does This Not Work Properly? The Sub CommandButton2_Click() code ensures that specific data has bee entered before allowing the user to continue, If not the Sub Exits, If they have entered the needed data then I wan to run the SaveLock Sub. However it will work up to the copy sheet to a new workbook part bu then stops. Why? Should I put something different to Call Savelock at the Else part of the first code? Private Sub CommandButton2_Click() Dim rng As Range Set rng = Range("E6,E16") If Application.CountA(rng) < 2 Then MsgBox "Please Complete At Least The Following" & Chr(13) & Chr(13) "Last Collection Call Date." & Chr(13) & "Lockout Prepared By." vbInformation, "IMPORTANT!" Exit Sub Else Call SaveLock End If End Sub Private Sub SaveLock() Dim LockOut LockOut = MsgBox("Are You Sure You Wish To Create Your Lockout Reques At This Time?", vbYesNo, "DAILY DRAT") If LockOut = vbNo Then End Sheets("Lockout").Select Sheets("Lockout").Copy ActiveWindow.DisplayHeadings = False Dim fn As Variant fn Application.GetSaveAsFilename(InitialFileName:=Wor ksheets("Lockout").Range("J2").Value FileFilter:="Excel Files (*.xls), *.xls", _ Title:="Save This Lockout Request Into Your Lockouts Folder! Do No Change The File Name Shown!") If TypeName(fn) = "Boolean" Then ActiveWorkbook.Close SaveChanges:=False Sheets("Lock6").Select MsgBox "Your Lockout Request WAS NOT Saved", vbOKOnly, "SAV CANCELLED!" Exit Sub End If ActiveWorkbook.SaveAs fn ActiveWorkbook.Close SaveChanges:=False ActiveWorkbook.Sheets("Dispatch").Select MsgBox "Your Lockout Request Has Been Saved And Closed." & Chr(13) "Please Email To Your District Manager For Processing!" End Sub I hope someone can help me with this. Thanks Celtic_Avenger :confused: :confused: :confused: :confused: :confused -- Celtic_Avenge ----------------------------------------------------------------------- Celtic_Avenger's Profile: http://www.excelforum.com/member.php...fo&userid=1410 View this thread: http://www.excelforum.com/showthread.php?threadid=26138 |
Why Wont This Work? VBA Help Needed!
However it will work up to the copy sheet to a new workbook part but
then stops. The code stops executing or the expected result is not seen in Excel? Arrange windows so you can see your code and the Excel UI (the workbooks) at the same time. Put a breakpoint at the line Sheets("Lockout").Copy (put your cursor on the line and press F9). Now run the code. When code execution stops, press F8. In the Excel UI, see if a new workbook was created with the copied sheet in it. Continue to step thru (F8) or run the code, checking to see that what you expect is happening. or if not why not. "Celtic_Avenger" wrote in message ... Why Does This Not Work Properly? The Sub CommandButton2_Click() code ensures that specific data has been entered before allowing the user to continue, If not the Sub Exits, If they have entered the needed data then I want to run the SaveLock Sub. However it will work up to the copy sheet to a new workbook part but then stops. Why? Should I put something different to Call Savelock at the Else part of the first code? Private Sub CommandButton2_Click() Dim rng As Range Set rng = Range("E6,E16") If Application.CountA(rng) < 2 Then MsgBox "Please Complete At Least The Following" & Chr(13) & Chr(13) & "Last Collection Call Date." & Chr(13) & "Lockout Prepared By.", vbInformation, "IMPORTANT!" Exit Sub Else Call SaveLock End If End Sub Private Sub SaveLock() Dim LockOut LockOut = MsgBox("Are You Sure You Wish To Create Your Lockout Request At This Time?", vbYesNo, "DAILY DRAT") If LockOut = vbNo Then End Sheets("Lockout").Select Sheets("Lockout").Copy ActiveWindow.DisplayHeadings = False Dim fn As Variant fn = Application.GetSaveAsFilename(InitialFileName:=Wor ksheets("Lockout").Range(" J2").Value, FileFilter:="Excel Files (*.xls), *.xls", _ Title:="Save This Lockout Request Into Your Lockouts Folder! Do Not Change The File Name Shown!") If TypeName(fn) = "Boolean" Then ActiveWorkbook.Close SaveChanges:=False Sheets("Lock6").Select MsgBox "Your Lockout Request WAS NOT Saved", vbOKOnly, "SAVE CANCELLED!" Exit Sub End If ActiveWorkbook.SaveAs fn ActiveWorkbook.Close SaveChanges:=False ActiveWorkbook.Sheets("Dispatch").Select MsgBox "Your Lockout Request Has Been Saved And Closed." & Chr(13) & "Please Email To Your District Manager For Processing!" End Sub I hope someone can help me with this. Thanks Celtic_Avenger :confused: :confused: :confused: :confused: :confused: -- Celtic_Avenger ------------------------------------------------------------------------ Celtic_Avenger's Profile: http://www.excelforum.com/member.php...o&userid=14101 View this thread: http://www.excelforum.com/showthread...hreadid=261382 |
All times are GMT +1. The time now is 09:30 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com