Skip to content

Instantly share code, notes, and snippets.

View mrowles's full-sized avatar
🎣
Gone fishing

Matthew Rowles mrowles

🎣
Gone fishing
View GitHub Profile
@mrowles
mrowles / ListFilesInDirectory.bas
Created December 11, 2012 22:52
Microsoft Excel: Finds all files in a specified directory with an optional specified criteria (extension, name)
Sub ListFilesInDirectory()
Dim fsFile, sFilename, sPath As String
Dim i As Integer
i = 2
'Set file attributes
sPath = "C:\"
sFilename = "*.pdf"
@mrowles
mrowles / ExcelErrorHandler.bas
Last active February 13, 2016 22:59
Microsoft Excel: Central Error Handler
'Global Error Varibles
Public bDisplayError As Boolean
Public sProcName, sDetails As String
Public iErrorCount As Integer
Public Function bCentralErrorHandler(ByVal sModule$, ByVal sSub$, ByVal sDetails$) As Boolean
'Make sure there is no errors in the Error Handling system
On Error Resume Next
@mrowles
mrowles / ChangeRowColor.bas
Last active October 13, 2015 22:08
Microsoft Excel: Changes the colour of a row based on a particular value in a cell
'Note: needs to be attached to a worksheet
Private Sub Worksheet_Change(ByVal Target As Range)
'Specifies the target column to pay attention to on worksheet change
If (Target.Column = 2) Then
'Conditional statement based on cell value
Select Case Target.Value
Case "red"
@mrowles
mrowles / CreateHTMLMsg.bas
Created December 11, 2012 22:36
Microsoft Outlook: Create a new email message from an HTML file
Sub CreateHTMLMsg()
Dim sLocation As String
'Change this to the location of your HTML file
sLocation = "C:\HTML_Template.html"
Set objMsg = Application.CreateItem(olMailItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(sLocation, 1)
@mrowles
mrowles / FormToXML.cs
Created May 10, 2012 03:12
Convert C# Form Data to XML File
Protected Sub FormToXML (ByVal sender As Object, ByVal e As System.EventArgs)
// Create the XML document object with specified parametres
Dim XMLDoc As XDocument
XMLDoc = New XDocument(
New XDeclaration("1.0", "utf-8", "yes"),
New XElement("user",
New XElement("details",
New XElement("firstname", Firstname.Text),
@mrowles
mrowles / CountWordsOccurrence.bas
Created May 10, 2012 03:07
Microsoft Word: Count occurrence of specific word/s in a document
Function CountWordsOccurrence() As Integer
Application.ScreenUpdating = False
Dim sWords As String
Dim iCount As Integer
'The word which is being counted
sWords = "word"