1. Runtime EXCEL VBA error handling code
Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
Sub My_Error_handlingCode()
On Error GoTo NitinPathError
Workbooks.Open Filename:="C:\Users\kumarnii\OneDrive - adidas\1-Master Database\01-Other Master Database 2015-2020\1_20_REEBOK_MASTER_DATABASE.xlsx"
Exit Sub
NitinPathError:
MsgBox ("Path Not Find/Not connect Internet, Pls check Internet connection")
End Sub
---------------------------------------------------------------------------------------------------------
2. UserForm show code:-
Below Code copy:-Green highlight text you can change
---------------------------------------------------------------------------------------------------------
Sub one_Click_list1()
Userform_name.Show
End Sub
----------------------------------------------------------------------------------------------------------
3. Open File Excel VBA code:-
Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
Sub myfileopen()
Workbooks.Open Filename:="C:\Users\kumarnii\OneDrive - adidas\1-Master Database\01-Other Master Database 2015-2020\1_20_REEBOK_MASTER_DATABASE.xlsx"
End Sub
---------------------------------------------------------------------------------------------------------
4. Open Folder VBA code:-
Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
Sub Nitinvbaapp_Setup()
Dim str_folder As String
str_folder = "C:\NitinVbaApp\Setup\"
Call Shell("explorer.exe " & str_folder, 3)
End Sub
-------------------------------------------------------------------------------------------------
5. File save as code:-
Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
Sub myfilesave()
ActiveWorkbook.SaveAs ("C:\DailyEntryCopy\myfilename.xlsx")
End sub()
-------------------------------------------------------------------------------------------------
6. Application Delay /Waiting Code:-
Below Code copy:-Green highlight text you can change
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
Sub myapplicationdelay()
' delay 2 secound
Application.Wait Now + TimeValue("00:00:02")
End sub()
-------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
Active Sheet Copy Excel Vba code:-
' Use for copy select sheet a new workbook for send mail.
Sub CopySheet()
Dim WB As Workbook
Dim AW As Window
Dim Newfilename As String
Dim Path1 As String
'ActiveWorkbook.Save
Path1 = "C:\DailyEntryCopy\"
If Dir(Path1, vbDirectory) = "" Then
Shell ("cmd /c mkdir """ & Path1 & """")
End If
'Application.Wait Now + TimeValue("00:00:02")
MsgBox ("file Save Location" & Path1)
Newfilename = InputBox("Enter File name ", "Enter a Number")
Set AW = ActiveWindow
For Each SHT In AW.SelectedSheets
Set TempWindow = AW.NewWindow
SHT.Copy
TempWindow.Close
Next
'Save file
ActiveWorkbook.SaveAs (Path1 & Newfilename & " " & Format(Now(), "DD-MMM-YYYY hh mm AMPM") & ".xlsx")
End Sub
------------------------------------------------------------------------------------------------------------------
Printout Excel VBA Code:-
'Below Pivot printout code you can record macro and change green code:-
----------------------------------------------------------------------------------------------
Sub PrintOutCarton()
'
' PrintOutCarton Macro
'
' Keyboard Shortcut: Ctrl+Shift+A
'
Range("b6").CurrentRegion.Select
Range("B6").Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End Sub
------------------------------------------------------------------------------------------------------