Using this template zip the multiple files with their folder name in one path.
Ex,
Assuming this path...... C:\Program Files\
In this folder it contain many folders.
Get directory list of folder names and give this list to this template under the name "FolderList:"
In "Your Path:" put the path above mentioned, (i.e., where the folders and files are located) and click the "GetZipfiles" button.
**Before using this template you must save as this file with the name "ConvertToZip.xls"
Click here to download ConvertToZip.xlt
Monday, December 20, 2010
LockCells with WorkSheet_Change event
Locking a cell is to prevent alteration of cell contents.
In excel go to Format|Cells... then select Protection tab and ensure the Locked tick box is Unchecked for your destination range of cells. Then use the Tools|Protection|Protect Sheet... to protect the sheet and any unlocked cells will be locked against alteration when the worksheet change.
Code:
This is a worksheet event code, which means that it needs to be placed in the appropriate worksheet code module, not a standard code module.
Option Explicit
Public Sub Worksheet_Change(ByVal Target As Range)
Call ApplyProtection(Range("A1:B20"))
Sheets("Sheet1").Protect Password:="password", UserInterfaceOnly:=True
End Sub
Private Sub ApplyProtection(thisRange As Range)
Dim thisCell As Range
ActiveSheet.Unprotect Password:="password"
For Each thisCell In thisRange
If IsEmpty(thisCell) Then
thisCell.Locked = False
Else
thisCell.Locked = True
End If
Next thisCell
ActiveSheet.Protect Password:="password", Contents:=True
End Sub
In excel go to Format|Cells... then select Protection tab and ensure the Locked tick box is Unchecked for your destination range of cells. Then use the Tools|Protection|Protect Sheet... to protect the sheet and any unlocked cells will be locked against alteration when the worksheet change.
Code:
This is a worksheet event code, which means that it needs to be placed in the appropriate worksheet code module, not a standard code module.
Option Explicit
Public Sub Worksheet_Change(ByVal Target As Range)
Call ApplyProtection(Range("A1:B20"))
Sheets("Sheet1").Protect Password:="password", UserInterfaceOnly:=True
End Sub
Private Sub ApplyProtection(thisRange As Range)
Dim thisCell As Range
ActiveSheet.Unprotect Password:="password"
For Each thisCell In thisRange
If IsEmpty(thisCell) Then
thisCell.Locked = False
Else
thisCell.Locked = True
End If
Next thisCell
ActiveSheet.Protect Password:="password", Contents:=True
End Sub
Tuesday, June 15, 2010
Need More Excel Tips?
Do you need more excel tips & tricks, 1000's of excel tips websites are available on net. Some of them I have listed here..
http://excel.tips.net
http://www.mrexcel.com
http://www.vbaexpress.com
http://www.tek-tips.com/index.cfm
http://www.databison.com
http://www.ozgrid.com
http://www.contextures.com
http://www.exceltip.com
http://www.mvps.org/dmcritchie/excel/excel.htm
http://spreadsheetpage.com
http://chandoo.org
http://www.jkp-ads.com
http://www.cpearson.com
http://www.jpsoftwaretech.com
http://www.mann-jones.com
http://jonlorenzini.com
http://www.erlandsendata.no/english
http://dailydoseofexcel.com
http://www.rondebruin.nl
http://www.toolbox.com
http://excel.tips.net
http://www.mrexcel.com
http://www.vbaexpress.com
http://www.tek-tips.com/index.cfm
http://www.databison.com
http://www.ozgrid.com
http://www.contextures.com
http://www.exceltip.com
http://www.mvps.org/dmcritchie/excel/excel.htm
http://spreadsheetpage.com
http://chandoo.org
http://www.jkp-ads.com
http://www.cpearson.com
http://www.jpsoftwaretech.com
http://www.mann-jones.com
http://jonlorenzini.com
http://www.erlandsendata.no/english
http://dailydoseofexcel.com
http://www.rondebruin.nl
http://www.toolbox.com
http://www.excelfunctions.net
http://www.excel-vba.com
http://www.excelforum.com
http://excelexperts.com
http://excelvbatutor.com
http://www.wizdoh.com
http://google.com
http://www.excel-vba.com
http://www.excelforum.com
http://excelexperts.com
http://excelvbatutor.com
http://www.wizdoh.com
Reversing a Cell Contents with VBA - MS Excel
Reversing active cell contents using the vba code. Place this code in to a standard module. Select the cell you want to reverse and run the macro.
Sub Reverse()
If Not ActiveCell.HasFormula Then
sRaw = ActiveCell.Text
sNew = ""
For J = 1 To Len(sRaw)
sNew = Mid(sRaw, J, 1) + sNew
Next J
ActiveCell.Value = sNew
End If
End Sub
Sub Reverse()
If Not ActiveCell.HasFormula Then
sRaw = ActiveCell.Text
sNew = ""
For J = 1 To Len(sRaw)
sNew = Mid(sRaw, J, 1) + sNew
Next J
ActiveCell.Value = sNew
End If
End Sub
LockCells with Workbook_BeforeSave event - MS Excel
Protecting cell contents to prevent loss of data/alteration of cell contents. This code will lock cells after saving the excel file. This is a worksheet event code, which means that it needs to be placed in the appropriate worksheet code module, not a standard code module. To do this, right-click on the sheet tab, select the View Code option from the menu, and paste the code in.
Before this you need to set up cell protection "Locked" to "Unlock" for all the cells you want to protect. To do this select the range of cells you want to protect and press Ctrl+1 for Format Cells, in the Protection tab un-tick the "Locked" check box then press OK.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ActiveSheet.Protect Contents:=False
For Each cell In Range("A1:M1000")
If cell <> "" Then cell.Locked = True
If cell = "" Then cell.Locked = False
Next
ActiveSheet.Protect Contents:=True
Sheets("Sheet1").Protect Password:="yourpassword"
Sheets("Sheet1").Protect UserInterfaceOnly:=True
Columns("A:J").AutoFit
End Sub
Creating desktop shortcut using VBA - MS Excel
Creating Desktop Shortcut:
Sub CreateShortCut()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Set oWSH = CreateObject("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
ActiveWorkbook.Name & ".lnk")
With oShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With
Set oWSH = Nothing
End Sub
Sub CreateShortCut()
Dim oWSH As Object
Dim oShortcut As Object
Dim sPathDeskTop As String
Set oWSH = CreateObject("WScript.Shell")
sPathDeskTop = oWSH.SpecialFolders("Desktop")
Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _
ActiveWorkbook.Name & ".lnk")
With oShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With
Set oWSH = Nothing
End Sub
The Cell function - MS Excel
The 'Cell' function returns information about the formatting, location, or contents of a cell.
Syntax:
Some examples...
To get the active worksheet name,
=MID(CELL("filename"),FIND("]",CELL("filename"))+1,255)
To get the active workbook name,
=MID(CELL("filename"),FIND("[",CELL("filename"))+1,(FIND("]",CELL("filename"))+1)-FIND("[",CELL("filename"))-2)
To get the path address & workbook name,
=CELL("filename")
To get the path address only,
=MID(CELL("filename"),1,FIND("[",CELL("filename"))-1)
Syntax:
CELL(info_type, [reference])
info_type - This is required field. A text value that specifies what type of cell information you want to return.
reference - This is optional field. The cell that you want information about. If omitted, the information specified in the info_type argument is returned for the last cell that was changed. If the reference argument is a range of cells, the CELL function returns the information for only the upper left cell of the range.
The info_type arguments are listed below,
Address - Reference of the first cell in reference, as text.
Col - Column number of the cell in reference.
Color - The value 1 if the cell is formatted in color for negative values; otherwise returns 0 (zero).
Contents - Value of the upper-left cell in reference; not a formula.
Filename - Filename (including full path) of the file that contains reference, as text. Returns empty text ("") if the worksheet that contains reference has not yet been saved.
Format - Text value corresponding to the number format of the cell. The text values for the various formats are shown in the following table. Returns "-" at the end of the text value if the cell is formatted in color for negative values. Returns "()" at the end of the text value if the cell is formatted with parentheses for positive or all values.
Parentheses - The value 1 if the cell is formatted with parentheses for positive or all values; otherwise returns 0.
Prefix - Text value corresponding to the "label prefix" of the cell. Returns single quotation mark (') if the cell contains left-aligned text, double quotation mark (") if the cell contains right-aligned text, caret (^) if the cell contains centered text, backslash (\) if the cell contains fill-aligned text, and empty text ("") if the cell contains anything else.
Protect - The value 0 if the cell is not locked; otherwise returns 1 if the cell is locked.
Row - Row number of the cell in reference.
Type - Text value corresponding to the type of data in the cell. Returns "b" for blank if the cell is empty, "l" for label if the cell contains a text constant, and "v" for value if the cell contains anything else.
Width - Column width of the cell, rounded off to an integer. Each unit of column width is equal to the width of one character in the default font size.
Some examples...
To get the active worksheet name,
=MID(CELL("filename"),FIND("]",CELL("filename"))+1,255)
To get the active workbook name,
=MID(CELL("filename"),FIND("[",CELL("filename"))+1,(FIND("]",CELL("filename"))+1)-FIND("[",CELL("filename"))-2)
To get the path address & workbook name,
=CELL("filename")
To get the path address only,
=MID(CELL("filename"),1,FIND("[",CELL("filename"))-1)
Capitalize the text in same cell - MS Excel
This is worksheet event code, which means that it needs to be placed in the appropriate worksheet code module, not a standard code module. To do this, right-click on the sheet tab, select the View Code option from the menu, and paste the code in.
VBA code for Capitalize the text in same cell:
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit
On Error GoTo ws_exit
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Value = UCase(.Value)
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
VBA code for Capitalize the text in same cell:
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit
On Error GoTo ws_exit
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
.Value = UCase(.Value)
End With
End If
ws_exit:
Application.EnableEvents = True
End Sub
Subscribe to:
Posts (Atom)