Posts

Showing posts from 2011

MsgBox function

Set images path in access

Function setImagePath()     Dim strImagePath As String     On Error GoTo PictureNotAvailable     strImagePath = Me.memProperyPhotoLink     Me.memProperyPhotoLink.Locked = True     Me.memProperyPhotoLink.Enabled = False     Me.ImageFrame.Picture = strImagePath     Exit Function PictureNotAvailable:     strImagePath = "C:\db_Images\NoImage.gif"     Me.ImageFrame.Picture = strImagePath End Function

Add image in MS-Access

Private Sub cmdAddImage_Click()     On Error GoTo cmdAddImage_Err     Dim strFilter As String     Dim lngflags As Long     Dim varFileName As Variant     strFilter = "All Files (*.*)" & vbNullChar & "*.*" _               & vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"     lngflags = tscFNPathMustExist Or tscFNFileMustExist _                Or tscFNHideReadOnly     varFileName = tsGetFileFromUser( _                   fOpenFile:=True, _                   strFilter:=strFilter, _                   rlngflags:=lngflags, _                   strDialogTitle:="Please choose a file...")     If IsNull(varFileName) Then     Else         Me![memProperyPhotoLink] = varFileName         Forms![frmProperties].Form.Requery     End If cmdAddImage_End:     On Error GoTo 0     Exit Sub cmdAddImage_Err:     Beep     MsgBox Err.Description, , "Error: " & Err.Number _                          

Color Function in excel sheet

Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean) Dim rCell As Range Dim lCol As Long Dim vResult lCol = rColor.Interior.ColorIndex     If SUM = True Then        For Each rCell In rRange         If rCell.Interior.ColorIndex = lCol Then                 vResult = WorksheetFunction.SUM(rCell) + vResult         End If        Next rCell     Else         For Each rCell In rRange         If rCell.Interior.ColorIndex = lCol Then                 vResult = 1 + vResult         End If        Next rCell End If ColorFunction = vResult End Function =ColorFunction($C$1,$A$1:$A$12,TRUE)

Rename current Sheet

ActiveSheet.Name = "Renamed14a" ActiveSheet.Name = "D" & Format(Date, "yyyymmdd") ActiveSheet.Name = "D" & Format(Range("a1"), "yyyymmdd") ActiveSheet.Name = "D" & Format(Range("a1"), "yyyy_mmdd_hhmm")

Create a New Workbook containing only one sheet

Workbooks.Add xlWorksheet  set newwb = workbooks.add(1)  set newwb = Workbooks.Add(xlWBATWorksheet)

Remove ALL commas

//Warning watch out for CSV file type data Sub WsReplaceLooseCommas()      Dim ws As Worksheet       For Each ws In ActiveWorkbook.Worksheets       ws.Cells.SpecialCells(xlCellTypeConstants, 2). _          Replace What:=",", Replacement:=" ", LookAt:=xlPart, _           SearchOrder:=xlByRows, MatchCase:=False       Next ws   End Sub

sheet color

Sub AllSheetsColorFormulas()     Dim sht As Worksheet     For Each sht In Sheets       On Error Resume Next 'in case no formulas       sht.Cells.SpecialCells(xlFormulas). _             Interior.ColorIndex = 6           Next sht   End Sub

Show sheet name

Sub MsgBoxAllMySheets()     Dim sht As Worksheet     For Each sht In Sheets       MsgBox sht.name     Next sht   End Sub

Open Excel File

Sub aa1() Dim xFilePath As Variant Dim xlFiles As Variant xFilePath = "E:\" xlFiles = Dir(xFilePath & "*.xls") Do While xlFiles <> "" Workbooks.Open Filename:=xFilePath & xlFiles xlFiles = Dir Loop End Sub