VIsual basic code

Joined
Feb 16, 2002
Messages
38
Hi Could I have the code for automatically saving and exiting a workbook also when this is done 250 times I would like a message box to come up to say a custom message
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Wow, impatient aren't we? It's only been 7 minutes from your first post, did you even try to solve it yourself?

<pre>
Public Sub Closeworkbooks()

Dim Wkbk As Workbook
Dim i As Integer

'Turn off alerts if you don't care about overwriting workbooks with the same names
Application.DisplayAlerts = False
For Each Wkbk In Workbooks
If Not Wkbk Is ThisWorkbook Then
Wkbk.Save
Wkbk.Close
i = i + 1
If i = 250 Then
MsgBox "250 workbooks have been closed by the impatient A Level Student."
End If
End If
Next
End Sub
</pre>
 
Upvote 0
Sub Exit_Save()
'
' Exit_Save Macro
' Exits And Saves The Excel Workbook
Dim Wkbk As Workbook
Dim i As Integer

'Turn off alerts if you don't care about overwriting workbooks with the same names
Application.DisplayAlerts = False
For Each Wkbk In Workbooks
If Not Wkbk Is ThisWorkbook Then
Wkbk.Save
Wkbk.Close
i = i + 1
If i = 2 Then
MsgBox "You have Saved Your Invoice 250 Times, It's Time To Save Your Invoice Onto Removeable Media"
End If
End If
Next
End Sub

'

This is the code I have entered on the VB editor but it doesn't work could you please give more assistance, thanks
 
Upvote 0
cant help you there. Whats your minor/major project about (im doing the NEAB's A2 in ICT myself). Mines an advanced student attainment system with loads of specialised reporting features, flashy little features,etc.
 
Upvote 0
wow thats pretty cool (the 250 bit i mean especially). Mine has an update students bit where it can take student records from one workbook to another by selecting a name from a combo box and a feature that auto-saves a workbook as a pre-defined workbook
 
Upvote 0

Forum statistics

Threads
1,223,516
Messages
6,172,778
Members
452,477
Latest member
DigDug2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top