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 / 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"
@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 / 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 / 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 / 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 / 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 / AccessErrorHandler.bas
Last active October 13, 2015 22:08
Microsoft Access: 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 / RefreshODBCLinks.bas
Last active December 15, 2015 06:39
Microsoft Access: The RefreshODBCLinks will refresh your ODBC connections each time you wish to make a query/connection to the backend database. In this example, the RefreshODBC function is called when opening the Access Database. It can also be called before using queries in your code to ensure the data is always correct and up to date and the …
@mrowles
mrowles / ExcelWorksheetExists.bas
Last active December 16, 2015 07:39
Microsoft Excel: This function checks if a Worksheet exists by accepting a Worksheet name as a parameter and looping through available worksheets. It will return false if the name is not found, otherwise it will return true if a Worksheet with the passed parameter exists. It is case-insensitive.
Function WorksheetExists(wsName As String) As Boolean
Dim ws As Worksheet
Dim found As Boolean
found = False
wsName = UCase(wsName)
For Each ws In ThisWorkbook.Sheets
If UCase(ws.Name) = wsName Then
@mrowles
mrowles / parseXML.js
Last active December 16, 2015 07:49
jQuery/JavaScript: Cycles an XML file on successful load via ajax and parses contents into HTML. In this example, we are using an Employee xml file with basic information parsing
/* Tested with jquery-1.7.2.min.js */
$(window).load(function () {
"use strict";
/* Cycles XML file on successful load via ajax and parses contents into HTML */
function parseXML(xml) {
/* Variable declaration */
var outHTML = "", employee, sId, sFirstname, sSurname, sAddress;