VBA拼写检查Excel中的特定单元格

除了别的之外,我正在使用一个macros来拼写检查我在Excel中创build的发票,然后保存它。 目前,它拼写检查整个工作簿。 我想拼写检查特定工作表的证书单元格(因为我不想拼写检查发票上的人名和地址)。

具体来说,我只想拼单检查表格“发票”中的单元格D15-D19和表格“安全检查”中的单元格D38,

有人能指出我正确的方向吗?

这是我正在使用的,我想提炼的VBA代码:

Option Explicit Sub SaveAsSafety() 'Saves filename as value of A1 plus the current date Application.CommandBars("Tools").Controls("Spelling...").Execute 'Invokes spell check Dim newFile As String, fName As String ' Don't use "/" in date, invalid syntax fName = Range("M9").Value 'Change the date format to whatever you'd like, but make sure it's in quotes newFile = fName & " - " & Range("D10").Value & " - " & Range("D9") ' Change directory to suit your PC, including USER NAME Sheets(Array("Safety Inspection", "Invoice")).Select Sheets("Safety Inspection").Activate ChDir _ "C:\Users\Brian\Google Drive\Buller Heating and Air\Invoices" ActiveWorkbook.SaveAs Filename:=newFile ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("A1").Value _ , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _ :=False, OpenAfterPublish:=False End Sub 

要检查特定单元格中的拼写,请尝试:

 Sub bbuller() Dim boo As Boolean s = Array("Invoice!D15", "Invoice!D16", "Invoice!D17", "Invoice!D18", "Invoice!D19", "'Safety Inspection'!D38") For Each ss In s boo = CheckItNew(Range(ss)) If boo Then MsgBox ss & " has no errors" Else MsgBox ss & " has errors" End If Next ss End Sub Public Function CheckItNew(r As Range) As Boolean Dim MyText As String MyText = r(1).Text Dim oxlAp As Object Set oxlAp = CreateObject("Excel.Application") CheckItNew = oxlAp.CheckSpelling(MyText) oxlAp.Quit Set oxlAp = Nothing End Function