Skip to content

Instantly share code, notes, and snippets.

@thoughtcroft
thoughtcroft / IsWordDocument.vb
Created August 2, 2016 00:41
2010-04-01-how-to-tell-if-a-file-is-a-word-document.md
Public Function IsWordDocument(ByVal strExtension As String) As Boolean
' Developed by Warren Bain on 01/04/2010
' Copyright (c) Thought Croft Pty Ltd
' All rights reserved.
' Verifies if the supplied file extension e.g. "doc"
' is recognised as one of the documents that this version
' of Word can natively handle. List is constructed from the
' types of documents that can be filtered in the Open File dialog
@thoughtcroft
thoughtcroft / IsFileOpen.vb
Created August 2, 2016 00:39
2008-08-27-is-that-file-open.md
Public Function IsFileOpen(ByVal strFullPathFileName As String) As Boolean
' Attempting to open a file for ReadWrite that exists will fail
' if someone else has it open. We also have to guard against the
' errors that occur if the file has uncommon file attributes such as
' 'hidden' which can upset the Open statement.
' NOTE: any open that doesn't lock the file such as opening a .txt file
' in NotePad or a read-only file open will return False from this call.
Dim lngFile As Long
@thoughtcroft
thoughtcroft / GeneratePassword.vb
Created August 2, 2016 00:37
2008-06-24-password-generator.md
Public Function GeneratePassword( _
ByVal intLength As Integer) As String
' Generates a random string of digits of the requested length
' In:
' intLength - number of digits to be returned (max 9)
' Out:
' Return Value - a random string of digits
' Example:
@thoughtcroft
thoughtcroft / AppState.vb
Created August 2, 2016 00:33
2008-06-19-automation-manager-class.md
' Class for defining an application state which can be
' saved and restored using the AppStateMgr class
' Developed by Warren Bain on 16/11/2006
' Copyright (c) Thought Croft Pty Ltd
' http:\\www.thoughtcroft.com
' All rights reserved.
Option Explicit
@thoughtcroft
thoughtcroft / tcStripChars.vb
Created August 2, 2016 00:26
2008-06-18-strip-types-of-characters-from-a-string.md
' Note: VBA6 is a conditional compiler constant that indicates
' the version of VBA and in this module we use enumerated types if
' supported otherwise we use plain old public constants
#If CBool(VBA6) Then
' Enumerate methods for selecting mode of character removal
Public Enum StripCharsMode
scmcRemoveAlphas = 2 ^ 0
scmcRemoveControl = 2 ^ 1
scmcRemoveNumerics = 2 ^ 2
@thoughtcroft
thoughtcroft / ThisOutlookSession.vb
Last active August 2, 2016 00:13
2008-03-19-automatic-account-assignment-in-outlook.md
Dim MyNewMailHandler As clsNewMailHandler
Private Sub Application_Quit()
Set MyNewMailHandler = Nothing
End Sub
Private Sub Application_Startup()
Set MyNewMailHandler = New clsNewMailHandler
End Sub
@thoughtcroft
thoughtcroft / CopyExcelData.vb
Created August 2, 2016 00:03
2007-10-12-copy-data-between-excel-workbooks.md
Public Sub CopyExcelData( _
ByRef wkbSource As Object, _
ByRef wkbTarget As Object, _
Optional ByVal blnCopyEmptyCells As Boolean = True)
'*** Change to remove control chars as it crashes Excel 97 ***'
' Copy all data entry cells from one workbook
' to the other assuming that a data entry cell
' is:
@thoughtcroft
thoughtcroft / ExampleUse.vb
Last active August 1, 2016 23:59
2007-03-01-how-to-tell-if-an-access-report-was-printed.md
Private rps As ReportPrintStatus
Private Sub Report_Close()
If rps.Printed Then
' Do something
End If
End Sub
Private Sub Report_Open(Cancel As Integer)
' Sink the reports events so we can determine if it was printed or not
@thoughtcroft
thoughtcroft / SetTextEditMode.vb
Last active February 27, 2021 02:21
2005-11-25-set-text-edit-mode.md
Public Enum TextEditMode
temcInvalid = 0
temcLockedTrue = 2 ^ 0
temcLockedFalse = 2 ^ 1
temcEnabledTrue = 2 ^ 2
temcEnabledFalse = 2 ^ 3
temcEnterWithEdit = temcLockedFalse + temcEnabledTrue
temcEnterNoEdit = temcLockedTrue + temcEnabledTrue
temcNoEnterNormal = temcLockedTrue + temcEnabledFalse
temcNoEnterDimmed = temcLockedFalse + temcEnabledFalse
@thoughtcroft
thoughtcroft / GetSubFormControlName.vb
Last active August 1, 2016 23:50
2005-11-25-get-subform-control-name.md
Public Enum ControlNameFormat
cnfcShortPropertyName
cnfcLongHierarchicalName
End Enum
Public Function GetSubFormControlName( _
ByRef frm As Form, _
Optional ByVal NameFormat As ControlNameFormat = _
cnfcShortPropertyName) As String