This code saves active sheet to temp file and then email it to the recipient. Once the mail has been sent the temp file is deleted by the code.
You will need to copy this code to regular VBA module of your workbook
|
Daily use tips for excel. Solution to frequently faced excel problems in simple manner.
|







|


Private Sub FloatingButton_Click()
Calander.Show
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = 1 Then
Exit Sub
ElseIf Target.Cells.Count > 1 Then
Exit Sub
Else
Set r = Target
Hasdate = 0
For x = -1 To 1
For y = -1 To 1
On Error GoTo Etrap1
If IsDate(r.Offset(x, y)) Then
Hasdate = 1
Exit For
End If
Rsume1:
Next y
If Hasdate = 1 Then Exit For
Rsume:
Next x
If Hasdate = 1 Then
FloatingButton.Left = r.Offset(0, 1).Left
FloatingButton.Top = r.Top
FloatingButton.Visible = True
Else
If Not FloatingButton.Visible = False Then
FloatingButton.Visible = False
End If
End If
Exit Sub
End If
Etrap1:
If r.Row = 1 Then
Resume Rsume
ElseIf r.Column = 1 Then
Resume Rsume1
End If
End Sub
Private Sub Worksheet_Activate()
Dim s As String
On Error Resume Next
s = ActiveSheet.FloatingButton.Caption
If Err.Number <> 0 Then
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=147.75, Top:=34.5, Width:=15.75, Height:= _
15.75).Select
Selection.Name = "FloatingButton"
ActiveSheet.OLEObjects("FloatingButton").Object.Caption = ""
ActiveSheet.OLEObjects("FloatingButton").Object.BackColor = &H80000005
Range("A1").Select
FloatingButton.Visible = False
End If
On Error GoTo 0
End Sub
|
Private Sub Workbook_Open()
Dim NewControl As CommandBarControl
Application.OnKey "+^{D}", "Module1.ShowCalander"
On Error Resume Next
Application.CommandBars("Cell").Controls("Show Date Picker").Delete
On Error GoTo 0
Set NewControl = Application.CommandBars("Cell").Controls.Add
With NewControl
.Caption = "Show Date Picker"
.OnAction = "Module1.ShowCalander"
.BeginGroup = True
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars("Cell").Controls("Show Date Picker").Delete
End Sub
|
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function ReleaseCapture Lib "user32" () As Long
Private Const GWL_STYLE As Long = (-16)
Private wHandle As Long
Sub ShowCalander()
Calander.Show
End Sub
|
| Text Data | Extracted Numeric Value |
| xusdhd 10005000 | 10005000 |
| AKSID0100050000 A1 | 100050000 |
| IU EW KFID100050000 A 1 | 100050000 |
| 10005 0000 A1 | 100050000 |
| 01000 A1 B 12 | 1000 |
|

|
|
Number | Formatted As |
10 | 10.00 |
100 | 100.00 |
1000 | 1,000.00 |
10000 | 10,000.00 |
100000 | 1,00,000.00 |
1000000 | 10,00,000.00 |
10000000 | 1,00,00,000.00 |
100000000 | 10,00,00,000.00 |
1000000000 | 1,00,00,00,000.00 |
10000000000 | 10,00,00,00,000.00 |
100000000000 | 1,00,00,00,00,000.00 |
|
1. Add sheet named Log in case it is does not exist in the file.
2. Record user activity based on events to Log sheet.
3. Along with recording a event, it records user information and time of event.
4. Manage log size and removes old entries while creating space for new entries.
5. User can view the log but can not make changes to the log.
|
|

|
You need to go step by step to open the file
1. Check if excel file is open
2. Open that file using VBA , This should be done only in case you know the full path for the particular file
3. In case you do not know the full path , it is advisable to give excel file open dialog and let user open the file.
Sub Open_File_after_IsOpen_or_Not() |
|
|
Add new column to the data only up to the last used row of exiting dateAdd new row to the data immediately after the last row so as you do not over write the exiting data.See the code below for the doing the activities as listed above.
Sub LastRowOfData() |
| Public Function MBSerialNumber() As String Dim objs As Object Dim obj As Object Dim WMI As Object Dim sAns As String Set WMI = GetObject("WinMgmts:") Set objs = WMI.InstancesOf("Win32_BaseBoard") For Each obj In objs sAns = sAns & obj.SerialNumber If sAns < objs.Count Then sAns = sAns & "," Next MBSerialNumber = sAns End Function |
| Private Sub Workbook_Open() Set RMBSN = Sheets(1).Range("C4") ' This is whare you have already stored required MBSerialNumber If MBSerialNumber <> RMBSN Then ' Checking if current machine serial number is matching with required MsgBox ("Data Security failier, This workbook will close") ' In case it does not match workbook will be closed ActiveWorkbook.Save ActiveWorkbook.Close End If End Sub |
| Private Sub Workbook_Open() Dim Edate As Date Edate = Format("31/08/2009", "DD/MM/YYYY") ' Replace this with the date you want If Date > Edate Then MsgBox ("This worksheet was valid upto " & Format(Edate, "dd-mmm-yyyy") & " and will be closed") ActiveWorkbook.Close End If If Edate - Date < 30 Then MsgBox ("This worksheet expires on " & Format(Edate, "dd-mmm-yyyy") & " You have " & Edate - Date & " Days left ") End If End Sub |
Function SpellCurr(ByVal MyNumber, _ |
Range("A1:A10").Select However if you put , between multiple ranges within the same line of the code you can select multiple ranges as given underRange("A1:A10,D1:D10,F1:F10").Select | Sub Multiple_ranges() Range("A1:A10").Select MsgBox ("Single Range Selected") Range("A1:A10,D1:D10,F1:F10").Select MsgBox ("Multiple Ranges Selected") Selection.Copy Range("A11").Select ActiveSheet.Paste End Sub |
|

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Msg").Visible = True
Sheets("Data").Visible = xlVeryHidden
End Sub
Private Sub Workbook_Open()
Sheets("Data").Visible = True
Sheets("Msg").Visible = xlVeryHidden
End Sub
ActiveWorkbook.Save
| Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim myCount 'This line of code is optional Dim i 'This line of code is optional On Error Resume Next myCount = Application.Sheets.Count Sheets(1).Visible = True Range("A1").Select For i = 2 To myCount Sheets(i).Visible = xlVeryHidden If i = myCount Then End If Next i ActiveWorkbook.Save End Sub Private Sub Workbook_Open() Dim myCount 'This line of code is optional Dim i 'This line of code is optional On Error Resume Next myCount = Application.Sheets.Count For i = 2 To myCount Sheets(i).Visible = True If i = myCount Then Sheets(1).Visible = xlVeryHidden End If Next i End Sub |
Macros in Excel : Learn Excel VBA : Objects
Macros in Excel : Learn Excel VBA : Methods
Macros in Excel : Learn Excel VBA : Properties
Myvariable = 28
Sub Explain_Variables()
Var_A = 10
Range("A4").Select ' Value of Cell A4 is 5
Var_B = ActiveCell
Var_Total = Var_A + Var_B
Range("A5") = Var_Total
End Sub