Monday, February 4, 2008

Change text to Proper case

To change text in a selected range to proper case use this code.

Sub ProperCase()
Dim cell As Range
For Each cell In Selection.Cells
If cell.HasFormula = False Then
cell = strconv(cell.text,vbProperCase)
End If
End Sub

To delete import error tables from database

Sub deleteimporterrors()

Dim tbldef As TableDef
For Each tbldef In CurrentDb.TableDefs
If Like "*_importerror*" Then
DoCmd.DeleteObject acTable,
End If
Next tbldef

End Sub

To Capture Last modified date of the file

If you want to capture last modified date of any file, you can use below code.

Sub test()
Dim fso As Object, myDir As String, fn As String, myFile As String, myDate As Date, maxDate As Date
Set fso = CreateObject("Scripting.FileSystemObject")
myDir = "C:\temp"
fn = Dir(myDir & "\*.csv)
Do While fn <> ""
myDate = fso.GetFile(myDir & "\" & fn).DateLastModified
If maxDate < myDate Then
myFile = fn
maxDate = myDate
End If
fn = Dir()
MsgBox myDir & "\" & fn & " : " & maxDate
End Sub