这个时候可能会用到下面的VBScript来强行加一个"'"来处理一下."'"的作用是强行转换为文本.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim workSheetsCount As Integer
Dim workSheetRowsCount As Integer
Dim workSheetColumnCount As Integer
Dim strValue As String
Dim Worksheet As Worksheet
Dim Workbook As Workbook
Set Workbook = Workbooks(1)
For workSheetsCount = 1 To Workbook.Worksheets.Count
Set Worksheet = Workbook.Worksheets(workSheetsCount)
For workSheetRowsCount = 1 To Worksheet.UsedRange.Cells.Rows.Count
For workSheetColumnCount = 1 To Worksheet.UsedRange.Cells.Columns.Count
strValue = Worksheet.Cells(workSheetRowsCount, workSheetColumnCount)
Worksheet.Cells(workSheetRowsCount, workSheetColumnCount) = "'" + strValue
Next
Next
Next
End Sub
用惯了C/C++的语法习惯,用VBScript还真不习惯,写个For循环都用了半天,ft!Dim workSheetsCount As Integer
Dim workSheetRowsCount As Integer
Dim workSheetColumnCount As Integer
Dim strValue As String
Dim Worksheet As Worksheet
Dim Workbook As Workbook
Set Workbook = Workbooks(1)
For workSheetsCount = 1 To Workbook.Worksheets.Count
Set Worksheet = Workbook.Worksheets(workSheetsCount)
For workSheetRowsCount = 1 To Worksheet.UsedRange.Cells.Rows.Count
For workSheetColumnCount = 1 To Worksheet.UsedRange.Cells.Columns.Count
strValue = Worksheet.Cells(workSheetRowsCount, workSheetColumnCount)
Worksheet.Cells(workSheetRowsCount, workSheetColumnCount) = "'" + strValue
Next
Next
Next
End Sub