
한 단어의 총 단어 수를 세어야 합니다.MS 엑셀파일. 일반적으로 MS Word나 PowerPoint에서는 상태 표시줄이나 속성 창에 표시됩니다. 그러나 Excel에서는 어디에도 제공되지 않습니다.
해결책이 있나요?
답변1
이를 위해 매크로를 만들 수 있습니다.
ALT + F11을 누르고 아래 코드를 입력하세요.
그런 다음 전체 시트를 선택하여 단어 수를 계산하기 위해 매크로를 실행합니다. 섹션을 선택하고 해당 섹션만 단어 수를 셀 수도 있습니다.
Sub CountWords()
Dim MyRange As Range
Dim CellCount As Long
Dim TotalWords As Long
Dim NumWords As Integer
Dim Raw As String
Set MyRange = ActiveSheet.Range(ActiveWindow.Selection.Address)
TotalWords = 0
For CellCount = 1 To MyRange.Cells.Count
If Not MyRange.Cells(CellCount).HasFormula Then
Raw = MyRange.Cells(CellCount).Value
Raw = Trim(Raw)
If Len(Raw) > 0 Then
NumWords = 1
Else
NumWords = 0
End If
While InStr(Raw, " ") > 0
Raw = Mid(Raw, InStr(Raw, " "))
Raw = Trim(Raw)
NumWords = NumWords + 1
Wend
TotalWords = TotalWords + NumWords
End If
Next CellCount
MsgBox "There are " & TotalWords & " words in the selection."
End Sub