0

I have a little issue with unwanted characters at the end of number. I mean "numerek". There is no blank space, because function Replace work and it is no help. I tried use function Trim, but still no help for me. For example "numerek" = "1121123123" and it is 13 characters for VBA, but there is no space and exactly we can see that there is 10 characters! When I use MsgBox (numerek) it gives "1121123123 " . How can I delete this " " characters, when I know that it is no blank space? This program has to give me all number without "blank space" but it is not blank space. I'm using it in Outlook VBA. Please help :)

Dim MyOlNamespace As NameSpace
Dim MySelectedItem As MailItem
Dim Response As String
Dim fso As Object, TmpFolder As Object
Dim tmpFileName As String
Dim wrdApp As Object
Dim wrdDoc As Object
Dim bStarted As Boolean
Dim dlgSaveAs As FileDialog
Dim fdfs As FileDialogFilters
Dim fdf As FileDialogFilter
Dim i As Integer
Dim WshShell As Object
Dim SpecialPath As String
Dim msgFileName As String
Dim strCurrentFile As String
Dim strName As String
Dim oRegEx As Object
Dim intPos As Long
Dim itm As Outlook.MailItem
Dim currentExplorer As Explorer
Dim Selection As Selection

Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim oldName

Dim file As String
Dim DateFormat As String
Dim newName As String
Dim numerek As String
Dim tytul_maila

Dim enviro As String

'Set currentExplorer = Application.ActiveExplorer
'Set Selection = currentExplorer.Selection

Set MyOlNamespace = Application.GetNamespace("MAPI")
Set MySelectedItem = ActiveExplorer.Selection.Item(1)
Set fso = CreateObject("Scripting.FileSystemObject")

serwer = "C:\Users\GZ76576\Documents\"

If InStr(MySelectedItem.Body, "faktury/rachunku") > 0 Then
wiersz = InStr(MySelectedItem.Body, "faktury/rachunku")
wiersz_koniec = InStr(MySelectedItem.Body, "Data wpływu")
    If wiersz_koniec > wiersz Then

numerek = Mid(MySelectedItem.Body, wiersz + 20, wiersz_koniec - wiersz - 24)
numerek = Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(numerek, ":", ""), "/", ""), "-", ""), "*", ""), "\", ""), " ", ""), " ", ""), "    ", ""), "|", ""), " ", ""), "_", "")


End If
End If

nrfaktury = InputBox("Wpisz numer" & vbNewLine & vbNewLine & "Zachowaj format" & vbNewLine & vbNewLine & "PRZYKLAD", , numerek)

If nrfaktury = "" Then
Exit Sub
End If
...
Grzegorz
  • 5
  • 4
  • You might take a look at [using a regular expression](https://stackoverflow.com/q/22542834/4088852) instead. – Comintern Aug 29 '18 at 15:32

1 Answers1

1

UPDATED based on clarified requirements of not truly wanting "numeric"

The below function allows you to list out exactly what characters you want to include in numerek. I filled in a couple letters for you to get you started. You could also try to leverage the character number, but it would probably take more time to research than to just type them out. Don't forget upper/lower case.

Sample results: =fixerThing("12 3b ") = "123b"

Function fixerThing(inputValue As String) As String
Dim i As Long, theCharacter As String

For i = 1 To Len(inputValue)

    theCharacter = Mid(inputValue, i, 1)

    Select Case theCharacter
        Case "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", _
         "e", "f" 'you can type out the rest.
            fixerThing = fixerThing & theCharacter

    End Select

Next i

End Function
pgSystemTester
  • 8,979
  • 2
  • 23
  • 49
  • Ok, big thanks for You it's working only for numbers, but what if: numerek = "RDY1012JG101" It can't read my "RDY" and "JG" and it read only "1012101" what should I do? – Grzegorz Aug 30 '18 at 07:24
  • @Grzegorz https://stackoverflow.com/questions/15723672/how-to-remove-all-non-alphanumeric-characters-from-a-string-except-period-and-sp maybe try this solution? – Kirszu Aug 30 '18 at 13:54
  • @PGCodeRider Thanks for answer, it's working and I clicked the green check, thank you one more time ;) – Grzegorz Aug 31 '18 at 12:12