Microsoft Developer Network >
Página principal de foros
>
Visual Basic General
>
Retrieve text from clipboard
Retrieve text from clipboard
- Hello,
I'm writing macro for the Visual Studio 2005 and I need to retrieve text from the clipboard.
How can I do this?
Thanks
Respuestas
- Hi again,
sorry i have made an mistake (the methods are shared ). Use this code ( i have tested it it works).
Edit: That works for Text/Unicode. If you need RTF/HTml you need to call the overloaded methods.Dim ClipBoardText As String If System.Windows.Forms.Clipboard.ContainsText Then ClipBoardText = System.Windows.Forms.Clipboard.GetText() End If
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marcado como respuestaJeff ShanMSFT, Moderadormiércoles, 11 de noviembre de 2009 6:28
- Propuesto como respuestaMaDFroG20091013 martes, 10 de noviembre de 2009 8:37
- This should paste the text on the clipboard:
DTE.ActiveDocument.Selection.Paste
as that is the code that the designer writes when recording a macro.
Normally a macro is recorded and then modified.- Marcado como respuestaJeff ShanMSFT, Moderadormiércoles, 11 de noviembre de 2009 6:26
- Propuesto como respuestaMaDFroG20091013 martes, 10 de noviembre de 2009 8:37
- Marcado como respuestaJeff ShanMSFT, Moderadormiércoles, 11 de noviembre de 2009 6:26
- Propuesto como respuestaMaDFroG20091013 martes, 10 de noviembre de 2009 8:37
Todas las respuestas
- Hi Jan,
you could use the System.Windows.Forms.Clipboard Class like:
Dim TheClipBoard as New System.Windows.Forms.Clipboard Dim ClipBoardText as String If TheClipBoard.ContainsText Then ClipBoardText = TheClipBoard.GetText() End If
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/ - Sorry, but this doesn't work. I've tried this code already, but without success.
The ContainsText property is allways set to false and calling GetText() method returns empty string. - Hi again,
sorry i have made an mistake (the methods are shared ). Use this code ( i have tested it it works).
Edit: That works for Text/Unicode. If you need RTF/HTml you need to call the overloaded methods.Dim ClipBoardText As String If System.Windows.Forms.Clipboard.ContainsText Then ClipBoardText = System.Windows.Forms.Clipboard.GetText() End If
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marcado como respuestaJeff ShanMSFT, Moderadormiércoles, 11 de noviembre de 2009 6:28
- Propuesto como respuestaMaDFroG20091013 martes, 10 de noviembre de 2009 8:37
Sorry, but still nohting.
I've copied text from - let's say notepad. Now I launch an macro in the VS2005 and try to get the text, but still the ContainsText property is false. Seems, that the Clipboard is empty. But why?- What are you doing different from this:
Clipboard.SetText("This is some text") Dim S As String = Clipboard.GetText
And make a few more duplicate posts: Get data from Clipboard in macro
- Propuesto como respuestaMaDFroG20091013 martes, 10 de noviembre de 2009 8:37
- Hi again,
i have tested it once again. I also used notepad and copied the text inside and the run my testapplication. It just worked fine. Btw i am also using VS2005.
Try the following: Create a new Windows Forms Project, place a button on the form and paste the code inside and run the application.
Edit: Btw, did you maybe call the Clear() method somewhere ?
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/ - I'm writing macro for the VS2005 -> try Alt+F11 ... that's the difference. I'm not writing windows form application
- You record the macro and it works, but when you play it back it doesn't. Is that the problem?
I write it by myself. Launch VS, Alt+F11, add code, Tools>Options>Keyboard -> find the macro (Macros.MyMacros.Module1.ConvertMethod) and add shortcut...
Sub ConvertMethod() Dim str As String ' str = Clipboard <<<- this is what i need ' process str DTE.ActiveDocument.Selection.Text = str End Sub- This should paste the text on the clipboard:
DTE.ActiveDocument.Selection.Paste
as that is the code that the designer writes when recording a macro.
Normally a macro is recorded and then modified.- Marcado como respuestaJeff ShanMSFT, Moderadormiércoles, 11 de noviembre de 2009 6:26
- Propuesto como respuestaMaDFroG20091013 martes, 10 de noviembre de 2009 8:37
- Marcado como respuestaJeff ShanMSFT, Moderadormiércoles, 11 de noviembre de 2009 6:26
- Propuesto como respuestaMaDFroG20091013 martes, 10 de noviembre de 2009 8:37

