Category: VBA Codes
VBA Code To Separate Filename From The Path
Dim fullPath() As String Dim wbIndex As Long Dim wbName as String Dim wbAddr as String ‘ Wbaddr holds the full path for example: ” D:\Documents and Settings\Desktop\Preeti\macro\Input.xls” fullPath() = Split(wbAddr, “\”) ‘Put Parts of the path into the array…
Macro To Delete Sheets From Workbook
To delete a sheet from the workbook without the user being prompted for confirmations, here is the code: Sub DeleteSheet ( ) Dim SheetName As String ‘ deletes a sheet named SheetName in the active workbook Application.DisplayAlerts…
VBA Code To Create A New Excel File By Deleting The Existing File
Sub CreateFile ( ) If fso.FileExists(wbAddr + “Output.xls”) Then Set wkOut = Workbooks.Open(wbAddr + “Output.xls”) Set wkOut = Workbooks(“Output.xls”) wkOut.Close fso.DeleteFile wbAddr + “Output.xls” End If Set wkOut = Workbooks.Add wkOut.SaveAs filename:=wbAddr + “Output.xls” Set wkOut…
VBA Code To Create An excel File
Sub CreateNewFile () Dim wkOut as Workbook Dim wbAddr as string Dim fso ‘wbAddr holds the path where the file needs to be created ‘like wbAddr=”D:\VbaCodes” Set fso = CreateObject(“Scripting.FileSystemObject”) Set wkOut = Workbooks.Add ‘Output.xls is the file to be…
VBA Code To Find Days In A Month
Sub findDays() Dim m As Integer, y As Integer Dim DaysInMonth As Integer m = Month(January) y = Year(2009) DaysInMonth = DateSerial(y, m + 1, 1) – DateSerial(y, m, 1) MsgBox “Days In Month…
Writing macros in Microsoft Excel using VBA
Hi All, A month back I was assigned a work in my office. The work required writing macros in Microsoft Excel using VBA. While doing that work i got to know many VBA codes, some of which i’ll be sharing with you.