macro automation scripts
macro automation scripts
This macro formats the entire worksheet by adjusting column widths, adding bold headers, and setting
gridlines.
Sub AutoFormatSheet()
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Cells.EntireColumn.AutoFit
ws.Rows(1).Font.Bold = True
ws.Cells.Borders.LineStyle = xlContinuous
End Sub
This macro removes duplicate values from Column A in the active worksheet.
Sub RemoveDuplicates()
Dim ws As Worksheet
Set ws = ActiveSheet
End Sub
3. Save All Sheets as Separate Files
This macro saves each worksheet as a separate Excel file in the same folder as the main file.
Sub SaveSheetsAsFiles()
Dim ws As Worksheet
ws.Copy
ActiveWorkbook.Close False
Next ws
End Sub
This macro sends an email with the active workbook as an attachment using Outlook.
Sub SendEmail()
Dim wb As Workbook
Set wb = ActiveWorkbook
With MailItem
.To = "recipient@example.com"
.Attachments.Add wb.FullName
.Send
End With
End Sub
Sub HighlightDuplicates()
Dim ws As Worksheet
Set ws = ActiveSheet
rng.FormatConditions.AddUniqueValues
rng.FormatConditions(1).DupeUnique = xlDuplicate
End Sub
1. Open Excel and press ALT + F11 to open the VBA Editor.
4. Close the VBA Editor and press ALT + F8 to run the macro.