| 1 |
Attribute VB_Name = "Module1" |
| 2 |
' VBA (Visual Basic for Applications) example |
| 3 |
' This would typically be found in Excel, Word, or Access |
| 4 |
|
| 5 |
Option Explicit |
| 6 |
|
| 7 |
Sub HelloWorld() |
| 8 |
' This is a VBA subroutine |
| 9 |
MsgBox "Hello from VBA!" |
| 10 |
End Sub |
| 11 |
|
| 12 |
Function AddNumbers(x As Integer, y As Integer) As Integer |
| 13 |
' VBA function to add two numbers |
| 14 |
AddNumbers = x + y |
| 15 |
End Function |
| 16 |
|
| 17 |
Private Sub Worksheet_Change(ByVal Target As Range) |
| 18 |
' Event handler - typical in VBA |
| 19 |
If Target.Address = "$A$1" Then |
| 20 |
Range("B1").Value = "Cell A1 was changed" |
| 21 |
End If |
| 22 |
End Sub |