删除不需要的字符

时间:2018-08-29 15:15:43

标签: excel vba outlook character

在数字末尾我有一个多余字符的小问题。我的意思是“ numerek”。没有空格,因为“替换工作”功能没有帮助。我尝试使用Trim函数,但对我仍然没有帮助。例如“ numerek” =“ 1121123123”,对于VBA,它是13个字符,但是没有空格,我们可以看到有10个字符!当我使用MsgBox(numerek)时,它显示为“ 1121123123”。当我知道它不是空格时,如何删除该字符?该程序必须给我所有没有“空格”的数字,但它不是空格。我在Outlook VBA中使用它。请帮忙:)

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
...

1 个答案:

答案 0 :(得分:1)

基于明确要求的更新,即不真正想要“数字”

以下功能可让您精确列出要包含在numerek中的字符。我给您写了几封信,以帮助您入门。您也可以尝试利用字符数,但是可能要花更多的时间来研究而不是仅仅输入字符。不要忘记大写/小写。

样本结果: =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