VBA Snippets


Message_DoesNotExist

Public Sub Message_NamedRangeDoesNotExist( _
ByVal snamedrange As String)

Dim sMessage As String
sMessage = "This workbook named range does not exist: " & _
vbCrLf & vbCrLf & _
"'" & snamedrange & "'"

Call MsgBox(sMessage, vbOKOnly + vbInformation, modConstants.g_sCOMPANYNAME & " (" & g_sVERSION & ") - " & "Named Range")
Call Tracer_Add("MESSAGE", sMessage)
End Sub

Wbk_NamedRangeGet

Public Function Wbk_NamedRangeGet( _
ByVal sWshName As String, _
ByVal sNamedRange As String, _
Optional ByVal bRemoveEquals As Boolean = True) As String

Const sPROCNAME As String = "Wbk_NamedRangeGet"
Dim owsh As Excel.Worksheet
Dim inamescounter As Integer

On Error GoTo ErrorHandler

owsh = Application.Worksheets(sWshName)
For inamescounter = 1 To owsh.Names.Count
If owsh.Names.Item(inamescounter).Name = sNamedRange Then
NamedRangeGet = owsh.Names.Item(inamescounter).Value
Exit For
End If
Next
If bRemoveEquals = True Then
NamedRangeGet = NamedRangeGet.Substring(1, NamedRangeGet.Length - 1)
End If

If gbDEBUG = False Then Exit Function
ErrorHandler:
Call Error_Handle(msMODULENAME, sPROCNAME, Err.Number, Err.Description, _
"return the contents of the named range '" & sNamedRange & "'.")
End Function

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top