Skip to content

Instantly share code, notes, and snippets.

View lopperman's full-sized avatar
😀

Paul Brower lopperman

😀
View GitHub Profile
function main(workbook: ExcelScript.Workbook) {
console.log("Checking for existance of Worksheet: 'vInfo'")
let infoSheet = workbook.getWorksheet("vInfo");
let toolsSheet = workbook.getWorksheet("vTools");
if (toolsSheet) {
console.log(workbook.getName() + " has vTools sheet");
let existTable = toolsSheet.getTable("tblVTOOLS");
if (!existTable) {
console.log("'tblVTOOLS' was not found -- creating now");
let newTable = workbook.addTable(toolsSheet.getUsedRange(), true);
UpdateContext({tbl1:ForAll(Filter(v3ProjectLog_Access,EntraId=Text(User().EntraObjectId)),'Log Area')})
//RETURNS OBJECT:Table, SINCE LOG AREA IS A LookUp, TABLE CONTAINS Id, VALUE COLUMNS
@lopperman
lopperman / Disable Macros on Programmatically Opened Workbook.vb
Last active August 11, 2024 21:47
Prevents Macros/VBA/auto_open from running on programatically opened Excel File
' Gist Link: https://gist.github.com/lopperman/622b5b20c2b870b87d9bd7606d3326f6
' ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ '
' author (c) Paul Brower https://github.com/lopperman/just-VBA
' license GNU General Public License v3.0
' ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ ~~~ '
'' REF: https://learn.microsoft.com/en-us/office/vba/api/excel.application.automationsecurity
'' Application.AutomationSecurity returns or sets an MsoAutomationSecurity constant
'' that represents the security mode that Microsoft Excel uses when
'' programmatically opening files. Read/write.
'' Excel Automatically Defaults Application.AutomationSecurity to msoAutomationSecurityLow
''This Formula takes a single row of values, and returns the first range column index in a range for each corresponding column
''Excel Lambda Function - Return Column Indexes of Matched Criteria
''This Formula takes a single row of values, and returns the first range column index in a range for each corresponding column
''e.g. given a worksheet with the following values
'' A B C D E F
''1
''2 2 4 1 1 2 0
''3 1 2 0
''4 2 3 1
@lopperman
lopperman / sharePoint_ThemePriorityColumnFormat.json
Created April 30, 2023 14:35
Format 1-5 Priority Column using current Site Theme
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"font-size": "16px"
},
"children": [
{
"elmType": "span",
"attributes": {
' []r/VBA -Article](https://www.reddit.com/r/vba/comments/w7cmm3/check_correctly_if_something_is_an_array_and_if/?utm_source=share&utm_medium=web2x&context=3)
' ~~~ Test if anything is and ARRAY ~~~
Public Function ValidArray(tstArr As Variant) As Boolean
Dim vt As Long: vt = VarType(tstArr)
Dim compare As Long
compare = vt And VbVarType.vbArray
ValidArray = compare <> 0
End Function
' ~~~ Check if array has been initialized (can read or set values) ~~~
@lopperman
lopperman / VBA_StringsMatch.bas
Created July 25, 2022 04:43
Handy 'StringsMatch' Method that handles Equal, Not Equal, Contains, StartsWith, EndsWith (Works with 'vbCompareMethod' Enum)
'POSTED WITH THIS ARTICLE ON REDDIT https://www.reddit.com/r/vba/comments/w74j85/handy_stringsmatch_method_that_handles_equal_not/?utm_source=share&utm_medium=web2x&context=3
Public Enum strMatchEnum
smEqual = 0
smNotEqualTo = 1
smContains = 2
smStartsWithStr = 3
smEndWithStr = 4
End Enum
Dim rng as Range: set rng = ThisWorkbook.Worksheets("your sheet name").Range("C6")
If GetFoundTextSheetRows(rng, ecOr, "apple", "application").Count = 1 Then
'delete the row
End If
Option Explicit
Public Enum ecCompType
ecOR = 0 'default
@lopperman
lopperman / just-VBA-because
Last active July 3, 2022 20:27
VBA-pbUtil is now just-VBA
<-- does one need a reason
<-- same code, less vanity
@lopperman
lopperman / ExportToPDF.txt
Created June 21, 2022 23:34
Export Worksheet To PDF
Public Function ExportSheetAsPDF(ws As Worksheet, fileName As String)
Dim saveDir As String
If Len(fileName) > 4 Then
If InStr(1, Right(fileName, 4), ".pdf", vbTextCompare) = 0 Then
fileName = fileName & ".pdf"
End If
End If
saveDir = ChooseFolder("select folder to save")
If Len(saveDir) > 0 Then