VBA - Visual Basic for Applications
Whenever I have to apply more complex text operations I tend to use regular expressions.
If you want to remove HTML tags from a String, nothing is faster and easier than using regular expressions to do so.
This code references the following API, which is a VBScript API.
"Microsoft VBScript Regular Expression Reference 5.5"
In order to reference this API in Excel VBA go to Options -> References (In German "Extras" -> "Verweise") and tick the API above.
- Hits: 5142
Determining the last row actually containing information in an Excel worksheet can be an annoying task, if you are relying on the Excel API to do the trick for you. Especially when you are not exatcly in control over the handed files you are dealing with and people are allowed to enter information anywhere it is not as easy as it should be.
Source Code automating Excel search function
Below function is determining the last row containing data in provided worksheet using the Excel search function.
This approach works only, if no cells in given sheet are merged.
Therefore merged cells are removed from a handed workbook before determining its last row containing data.
- Hits: 4961
If you need to reference a workbook, which might already be opened but all you have ready is the file path the following function will do the trick for you.
If the Excel workbook is not opened oran opened workbook with the same name is not saved under given file path, Nothing will be returned.
' @Author - Alexander Bolte
' @Change Date - 2013-12
' @Description - Returns a workbook object referencing an Excel file
' available under given file path, if the Excel file was already opened before calling this function.
' @Param filePath - a path to an Excel file.
' @Returns - a workbook object referencing an Excel file available under given file path.
Public Function getOpenedWorkbook(ByVal filePath As String) As Workbook
Dim ret As Workbook
Dim wrkName As String
Dim sep As String
Dim splitted() As String
On Error GoTo errHandle:
' Get the separator for path strings on operating system.
sep = Application.PathSeparator
splitted = Split(filePath, sep)
wrkName = splitted(UBound(splitted))
Set ret = Application.Workbooks(wrkName)
If ret.path <> filePath Then
ret = Nothing
If Err.Number <> 0 Then
Set getOpenedWorkbook = ret
- Hits: 5091
Excel VBA Article Count: 30
This category will hold articles regarding developement in Excel VBA. It will serve as a wiki and an Excel VBA Framework for myself.
Some development tasks reoccur for every customer. Since I am a lazy bum it will be nice to have a central source where I can reuse source code from.
MS Office and VBA Article Count: 11
This category holds articles regarding general things in MS Office VBA independent from the MS Office application.
Power Point VBA Article Count: 1
Page 7 of 17