0

Word 2007(またはWord 2003)VBAを使用してすべてのテキストをコピーし、4行のcsvドキュメントに貼り付ける方法。例:「私は世界が大好きです」。そうなる:

I -    Line 1 - page 1 - Paragraph 1
love - Line 1 - page 1 - Paragraph 1
the -  Line 1 - page 1 - Paragraph 1
word - Line 1 - page 1 - Paragraph 1
4

1 に答える 1

1

次のコードは.csvファイルに出力されます。

ノート!まず、Microsoft Scripting Runtime dll(scrrun.dll)への参照を追加してください

VBAウィンドウから[ツール]->[参照]->[MicrosoftScriptingRuntimedllの確認]

動作するコードは次のとおりです(マクロを作成してその中にコードを配置できます)。

Dim wordsArray, arrayElement
Dim delimiter As String
Dim fileName As String
Dim fso As FileSystemObject
Dim outputFile As textStream

'select all document's content
ActiveDocument.Select

'provide delimiter
delimiter = InputBox("Please enter delimiter to use")

'split the selected content and place it inside the array
wordsArray = Split(Selection.Text, delimiter)

'generate output file name
fileName = "C:\Output.csv"

'create new FileSystem object and open text stream to write to
Set fs = New FileSystemObject
Set outputFile = fs.CreateTextFile(fileName, True) 'note file will be overwritten

'iterate through array and write to the file
For Each arrayElement In wordsArray
    'Use the following code to place each word into separate COLUMN
    'outputFile.Write (arrayElement) & ","

    'Use the following code to place each word into separate ROW
    outputFile.WriteLine (arrayElement)
Next

'close output stream
outputFile.Close

あなたのニーズに基づいてそれをマッサージすることができます...

お役に立てれば。

于 2011-07-06T22:57:52.093 に答える