Can I save clipboard contents as .txt file?

D

Dave B

Can I save the contents of the clipboard as a .txt file, or do I need to
open Notepad, paste the contents in, and then save it? Can anyone tell me
how to do this? Thanks.
 
C

Charles Maxson

Here's some code that will do that....




Sub OutputClipboardToText()

Dim txt As Shape
Dim sFileName As String
Dim iOutput As Integer

Set txt =
ActiveDocument.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal,
Left:=10, Top:=10, Width:=100, Height:=200)

txt.TextFrame.TextRange.PasteAndFormat (wdFormatPlainText)

sFileName = "Clipboard.txt"
Open sFileName For Output As #1
Print #1, txt.TextFrame.TextRange.Text
Close

txt.Delete


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top