Skip to content

Instantly share code, notes, and snippets.

@supergrass71
supergrass71 / keybase.md
Created February 14, 2019 11:28
keybase.md

Keybase proof

I hereby claim:

  • I am supergrass71 on github.
  • I am mjn (https://keybase.io/mjn) on keybase.
  • I have a public key ASBgpJ6qJIkK8yqkhT17HjieFEyIRBdF2gNc2936LVcd3Qo

To claim this, I am signing this object:

@supergrass71
supergrass71 / Document_Cleanse.bas
Last active March 12, 2019 13:18
[Loop Folders & SubFolders] Loop through a folder and act on specific files in that folder #VBA #Excel #Word
Attribute VB_Name = "Document_Cleanse"
Option Explicit
Sub LoopFolder()
'from https://www.mrexcel.com/forum/excel-questions/866125-vba-loop-through-all-files-all-subfolders.html
Dim fso As New FileSystemObject
Dim f As Folder, sf As Folder
Dim ofile As File
Dim MyPath As String, RootFolder As String
@supergrass71
supergrass71 / addhyperlinkedsheet.bas
Last active March 12, 2019 13:25
[Create A Hyperlink to a sheet based on Cell Value] Add Hyperlinked Page #VBA #Excel
Sub createNewStepsWorksheet()
Dim totalSheets As Integer
Dim sheetName As String
sheetName = ActiveCell.Value
With ActiveWorkbook
totalSheets = .Worksheets.Count
.Sheets(2).Copy After:=Sheets(totalSheets)
@supergrass71
supergrass71 / AddValidation.bas
Last active March 12, 2019 13:25
[Cell Validation on the fly] Dynamically Add Data Validation to a Column of Cells #VBA #Excel
Sub AddValidation(cell as range)
'designed to work in tandem with worksheet function (see next)
If cell.rows.count>1 or cell.columns.count>1 then exit sub
With cell.validation
.delete
.add Type:=xlValidateList, AlertStyle:=xlValidateAlertStop, Operator: _
xlBetween, Formula:="A,list,of,your,values"
.ignoreblank = True
.incelldropdown = true
@supergrass71
supergrass71 / RemoveHyperlinks.bas
Last active March 12, 2019 13:26
[Remove Hyperlinks] #VBA #Visual Basic
@supergrass71
supergrass71 / squareCells.bas
Last active March 16, 2019 11:26
[make a square cell grid] constructs a grid mad of square cells e.g. graph paper #vba, #excel
Sub MakeSquareCells()
'// Create graph paper in Excel see http://www.erlandsendata.no/english/index.php?d=envbawssetrowcol
'if you want cm or inches
Dim noOfColumns As Integer, squareSide As Integer, i As Integer
noOfColumns = Application.InputBox(Prompt:="Select number of columns for grid (from column A:)", _
Title:="Square Grid Maker", Default:=1, Type:=1)
squareSide = Application.InputBox(Prompt:="Select width (mm:", _
Title:="Square Grid Maker", Default:=1, Type:=1)
Application.ScreenUpdating = False
With Activesheet
@supergrass71
supergrass71 / FindReplaceAnywhere.bas
Created October 25, 2019 08:43
Find Replace Anywhere #Word
Public Sub FindReplaceAnywhere() 'https://wordmvp.com/FAQs/Customization/ReplaceAnywhere.htm Dim rngStory As Word.Range Dim pFindTxt As String Dim pReplaceTxt As String Dim lngJunk As Long Dim oShp As Shape
pFindTxt = InputBox("Enter the text that you want to find.", "FIND")
If pFindTxt = "" Then
MsgBox "Cancelled by User"
Exit Sub
End If
TryAgain: pReplaceTxt = InputBox("Enter the replacement.", "REPLACE")
If pReplaceTxt = "" Then
If MsgBox("Do you just want to delete the found text?", vbYesNoCancel) = vbNo Then
GoTo TryAgain
@supergrass71
supergrass71 / addScreenTip.bas
Created October 27, 2019 09:56
Add Screen Tip
Sub addScreenTip(doc As Document, rng As Range, bmark As String, tip As String)
'add bookmark
With doc.Bookmarks
.Add Range:=Selection.Range, Name:=bmark
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
End Sub
@supergrass71
supergrass71 / CleanTrim.bas
Created October 27, 2019 09:58
Clean Trim #Word
Function CleanTrim(ByVal S As String, Optional ConvertNonBreakingSpace As Boolean = True) As String
'https://www.mrexcel.com/forum/excel-questions/923725-vba-remove-all-non-printable-special-characters-well-trim.html
Dim X As Long, CodesToClean As Variant
CodesToClean = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, _
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 127, 129, 141, 143, 144, 157)
If ConvertNonBreakingSpace Then S = Replace(S, Chr(160), " ")
For X = LBound(CodesToClean) To UBound(CodesToClean)
If InStr(S, Chr(CodesToClean(X))) Then S = Replace(S, Chr(CodesToClean(X)), "")
Next
CleanTrim = S
@supergrass71
supergrass71 / createnote2.bas
Last active October 27, 2019 09:58
Hover Text #Word
Sub createNote2()
'based on https://wordribbon.tips.net/T013230_ScreenTips_without_Hyperlinks
'uses acronym module instead of user inputbox
Dim timeStamp As String, bookmarkName As String, screentipText As String, key As String
Dim rng As Range
Dim answer As Integer
Dim tbl As Table
Application.ScreenUpdating = False
timeStamp = Format(Now(), "yyyyMMddHHmmss")
'On Error GoTo ErrHandler