使用VBA将包裹的文本转换为正常



我需要一个VBA代码将包装的文本转换为普通文本。它的痛苦复制到记事本b的粘贴。预先感谢。

Sub unwrap()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim str As String
    For Each char In ActiveSheet.UsedRange
        str = char.Value
        If Trim(Application.Clean(str)) <> str Then
            str = Trim(Application.Clean(str))
            char.Value = str
        End If
    Next
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub

在黑暗中拍摄

这是您正在尝试的吗?

Sub Sample()
    Dim ws As Worksheet
    Dim nCalc As Long
    On Error GoTo Whoa
    Application.ScreenUpdating = False
    nCalc = Application.Calculation
    Application.Calculation = xlCalculationManual
    '~~> Replace this with the actual sheet name
    Set ws = ThisWorkbook.Sheets("Sheet1")
    With ws
        .Cells.Replace What:=Chr(160), _
        Replacement:="", _
        LookAt:=xlPart, _
        SearchOrder:=xlByRows, _
        MatchCase:=False
    End With
LetsContinue:
    Application.ScreenUpdating = True
    Application.Calculation = nCalc
    Exit Sub
Whoa:
    MsgBox Err.Description
End Sub

最新更新