Buffer Stock Management System
Buffer Stock Management System
Option Explicit
'===================================
' Main Procedures
'===================================
Sub Initialize()
' Set worksheet references
Set wsData = ThisWorkbook.Sheets("Inventory")
Set wsCategories = ThisWorkbook.Sheets("Categories")
Set wsSettings = ThisWorkbook.Sheets("Settings")
Sub AddStock()
' Add stock to selected item
Dim selectedRow As Long
Dim quantityToAdd As Long
Sub SubtractStock()
' Subtract stock from selected item
Dim selectedRow As Long
Dim quantityToSubtract As Long
Dim currentStock As Long
Sub AddNewItem()
' Add a new item to inventory
Dim newRow As Long
Dim itemName As String
Dim category As String
Dim leadTime As String
Dim minStock As Long
Sub SendLowStockEmail()
' Send email for low stock items
Dim objOutlook As Object
Dim objMail As Object
Dim strBody As String
Dim strSubject As String
Dim lastRow As Long
Dim i As Long
Dim lowStockCount As Long
Dim recipientEmail As String
On Error GoTo 0
With objMail
.To = recipientEmail
.Subject = strSubject
.Body = strBody
.Display ' For testing - change to .Send for automatic sending
End With
Sub ScheduleWeeklyEmail()
' Set up a weekly scheduled task to send emails
' Note: This requires Windows Task Scheduler to be set up separately
MsgBox "To schedule weekly emails, please create a Windows Task Scheduler task
that runs this Excel file with the /e switch and the macro name
'SendLowStockEmail'." & vbCrLf & _
"Example command: Excel.exe ""C:\path\to\this\file.xlsm"" /e
SendLowStockEmail", vbInformation
End Sub
'===================================
' Helper Functions
'===================================
' First identify items with "More than 1 month" lead time
For i = 5 To lastRow
If wsData.Cells(i, 4).Value <= wsData.Cells(i, 6).Value And _
wsData.Cells(i, 5).Value = "More than 1 month" Then
longLeadTimeItems.Add i
End If
Next i
For i = 1 To longLeadTimeItems.Count
Dim row As Long
row = longLeadTimeItems(i)
GetCriticalItems = criticalItems
End Function
Sub CreateCategoriesDropdown()
' Create data validation for categories dropdown
Dim categoriesRange As String
Dim lastCatRow As Long
Sub CreateLeadTimeDropdown()
' Create data validation for lead time dropdown
Dim leadTimes As String
Sub FormatInventoryTable()
' Format the inventory table
With wsData.Range("A4:G4")
.Value = Array("ID", "Item Name", "Category", "Current Stock", "Lead Time",
"Min Stock", "Last Modified")
.Font.Bold = True
.Interior.Color = RGB(200, 200, 200)
End With
Sub AddFormButtons()
' Add control buttons to the sheet
Dim btn As Button
Sub CreateLowStockFormatting()
' Create conditional formatting for low stock items
Dim inventoryRange As Range
Dim lastRow As Long
Sub SetupWorkbook()
' Create the initial workbook structure
ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)).Name
= "Inventory"
Set wsData = ThisWorkbook.Sheets("Inventory")
End If
ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)).Name
= "Categories"
Set wsCategories = ThisWorkbook.Sheets("Categories")
End If
ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)).Name
= "Settings"
Set wsSettings = ThisWorkbook.Sheets("Settings")
End If
On Error GoTo 0
' Setup Categories worksheet
wsCategories.Range("A1").Value = "Categories"
wsCategories.Range("A1").Font.Bold = True
wsCategories.Range("A2").Value = "Electronics"
wsCategories.Range("A3").Value = "Office Supplies"
wsCategories.Range("A4").Value = "Furniture"
wsCategories.Range("A5").Value = "Food & Beverage"
wsCategories.Range("A1").EntireColumn.AutoFit
Sub FilterByLeadTime()
' Filter inventory by lead time
Dim leadTime As String
leadTime = wsData.Range("K2").Value
Sub ShowCriticalItems()
' Filter to show items that are almost out of stock and have longest lead time
'===================================
' Workbook Events
'===================================