开发者

Word VBA Macro -- Write multiple items to a txt file?

I'm working on a project to store what a user cuts/cop开发者_如何学Pythonies/pastes within a Word document, and am using the VBA macros to accomplish this. Here's a snippet from the paste macro:

Open "C:\Temp\HoldPastes.txt" For Output As #1
      Write #1, "TestTestTest."
      Write #1, Selection
      Close #1

I'd like HoldPastes.txt to have a list of every chunk of text the user has pasted.

First off, Write #1, Selection is wrong; it puts two quotation marks into my txt file. How can I access what's been pasted from the clipboard and write that to my file?

Also, this overwrites whatever I had in HoldPastes.txt. I'd like to preserve all pastes in this file, so how can I tell the macro to pick up where it left off and add to the file?


Append to a file is not For Output but For Append

Open "C:\Temp\HoldPastes.txt" For Append As #1

Read the Clipboard

Dim myData As DataObject
Dim strClip As String

Set myData = New DataObject
myData.GetFromClipboard
strClip = myData.GetText

Hope this helps


instead of: write #1, "text" you need to use: print #1, "text"

the write command will always use " marks around the data being saved to the file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜