12
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VBScriptで分かち書きを実行(MS標準機能のみで実装)

Last updated at Posted at 2014-04-05

#概要
VBScriptによるInternetExplorerクローラー化サンプルに関連して、
Webサイトのテキストを分かち書き(単語ごとにスペースで区切る形)で出力できたら面白そう。
簡単なテキストマイニングができる。

指定の1文を分かち書きで表示するVBScriptコードを書いた。
Windows・MSOfficeの標準機能のみでの実装で、職場でも安心実行!

#前提
・MeCab? 知らない子ですね。
・MSWordなら知っています。

#コード

分かち書き.vbs
Option Explicit

Dim doc
Set doc = CreateObject("Word.Application").Documents.Add()
Dim rng
Set rng = doc.Paragraphs(1).Range

rng.Text = "サンプルの文章です。半角スペースで区切られます。"

Dim wrd
Dim aryWrd()
Dim i
i = 0
For Each wrd In rng.Words
    ReDim Preserve aryWrd(i)
    aryWrd(i) = wrd.Text
    i = i + 1
Next

doc.Close False
Set doc = Nothing

MsgBox(Join(aryWrd," "))

#参考
Excelで自然言語処理: VBA自作関数でわかち書きしてみる

12
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?