使用vba将包装文本转换为正常

时间:2014-01-30 07:10:04

标签: excel-vba vba excel

我需要一个vba代码才能将包装文本转换为普通文本。它的痛苦复制到记事本n粘贴回来。 提前谢谢。

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

1 个答案:

答案 0 :(得分:1)

在黑暗中拍摄

这是你在尝试的吗?

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