Hi all,
How would I be able to delete a character or blank (empty)
spaces within a variable? I've used Trim, LTrim and Mid,
but it doesn't work with the specific value I need to change.
I've created a Macro to search for a specific
number format using MS Word 97. If the specific number format is found, then the actual number is selected and passed to a variable. The number found is in format #anynumber, anynumber...
I need to delete the # (pound) sign after finding the number.
I've provided a sample code and comments for analysis.
Thanks in advance for the help. Peace!
SAMPLE CODE:
' The number format to search for. Note: ^# = any number
' example: #^#^#^#^#^# might equal #12345
Invoice7 = "#^#^#^#^#^#^#^#"
' The search
Set SearchInv = ActiveDocument.Content
SearchInv.Find.Execute FindText:=Invoice7 Forward:=True
If SearchInv.Find.Found = True Then
SearchInv.Select
' The variable name if number format is found
Dim InvDocName
InvDocName = SearchInv
' The Function to search for the # sign and delete it.
' ***This is where I need help.***
Private Function CleanInv(TheInv)
' use LEFT to check first character of number
' for # (pound) sign
If Left(TheInv, 1) = "#" Then
' if found, use mid to replace the # sign with an empty space
' *This is where I have a problem as using Mid Statement gets
' rid of the # (pound) sign, but then creates an empty space*
Mid(TheInv, 1, 1) = ""
' finally, delete the empty space using TRIM function
' and return the value of the function
' Note: This however, does not delete the empty space
TrimmedInv = Trim(TheInv)
CleanInv = TrimmedInv
Else
CleanInv = TheInv
End If
End Function
' NOTE: The FUNCTION 'CleanInv' works perfectly
' with the SUB below. However, it doesn't work at
' all in the above example.
Sub Testing123()
InvDocName = "#7772225"
Call CleanInv(TheInv)
Debug.Print CleanInv(InvDocName)
End Sub
' InvDocName will then equal "7772225"
Thanks again for any help. Peace!
How would I be able to delete a character or blank (empty)
spaces within a variable? I've used Trim, LTrim and Mid,
but it doesn't work with the specific value I need to change.
I've created a Macro to search for a specific
number format using MS Word 97. If the specific number format is found, then the actual number is selected and passed to a variable. The number found is in format #anynumber, anynumber...
I need to delete the # (pound) sign after finding the number.
I've provided a sample code and comments for analysis.
Thanks in advance for the help. Peace!
SAMPLE CODE:
' The number format to search for. Note: ^# = any number
' example: #^#^#^#^#^# might equal #12345
Invoice7 = "#^#^#^#^#^#^#^#"
' The search
Set SearchInv = ActiveDocument.Content
SearchInv.Find.Execute FindText:=Invoice7 Forward:=True
If SearchInv.Find.Found = True Then
SearchInv.Select
' The variable name if number format is found
Dim InvDocName
InvDocName = SearchInv
' The Function to search for the # sign and delete it.
' ***This is where I need help.***
Private Function CleanInv(TheInv)
' use LEFT to check first character of number
' for # (pound) sign
If Left(TheInv, 1) = "#" Then
' if found, use mid to replace the # sign with an empty space
' *This is where I have a problem as using Mid Statement gets
' rid of the # (pound) sign, but then creates an empty space*
Mid(TheInv, 1, 1) = ""
' finally, delete the empty space using TRIM function
' and return the value of the function
' Note: This however, does not delete the empty space
TrimmedInv = Trim(TheInv)
CleanInv = TrimmedInv
Else
CleanInv = TheInv
End If
End Function
' NOTE: The FUNCTION 'CleanInv' works perfectly
' with the SUB below. However, it doesn't work at
' all in the above example.
Sub Testing123()
InvDocName = "#7772225"
Call CleanInv(TheInv)
Debug.Print CleanInv(InvDocName)
End Sub
' InvDocName will then equal "7772225"
Thanks again for any help. Peace!