以下是一个可以实现您要求的VBA代码:

Sub ConvertToText()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim lastCol As Long
    Dim cell As Range
    
    'Loop through all workbooks in the folder
    For Each wb In Workbooks
        'Loop through all worksheets in the workbook
        For Each ws In wb.Worksheets
            'Find the last row and column with data
            lastRow = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            lastCol = ws.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
            
            'Loop through all cells with data and convert formulas to values
            For Each cell In ws.Range(ws.Cells(1, 1), ws.Cells(lastRow, lastCol))
                If cell.HasFormula Then
                    cell.Value = cell.Value
                End If
                cell.NumberFormat = "@"
            Next cell
        Next ws
    Next wb
End Sub

将此代码复制到您的Excel VBA编辑器中,然后按F5运行。它将循环遍历您所选的文件夹中的所有Excel文件,并将每个工作表中的单元格转换为文本格式并删除公式

我有一个文件夹里面都是excel我想用一个vba代码 让每个excel表格的单元格都变成文本文字不含公式

原文地址: https://www.cveoy.top/t/topic/c0I0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录