Answer» This should be a pretty simple question for anyone familiar with MSVB functions. I'm pretty good with them, but I just don't use it enough to know what this particular function is called...
The Question: Is there a way to create a STRING in VB and then place it onto the copy/paste clipboard? For example, I run a macro that generates a string, and then the macro places the string onto the clipboard so that I can paste it wherever I want with Ctrl-V?
It would look something like this:
sub KineticsMacro()
Dim KineticsString As String KineticsString = "Hello World"
end sub Then when I press Ctrl-V, the string "Hello World" will paste into whatever document I have open.
And for those of you that require more information...
The situation: I have a word document with about 50 CHECK boxes in it. The client takes this form, checks off the applicable boxes, and resubmits it to me. More often than not, 30 or more checkboxes will be checked. To dummy-proof the form (for the client & people on my team), the document is to remain in "Locked/Secure" mode at ALL TIMES, and each checkbox was created as a VB object so that macros could be assigned to them.
The problem: When I get this form, I need to copy the information from the form into a database, including a list of everything that was checked. Unfortuneately, since the document is always Locked-down, you can only highlight/copy/paste text that resides in designated unprotected "free text" areas. Since we can't risk a client changing the text for each checkbox, we have no way of performing a copy/paste from the form into our database... ...and entering 30 or more sever names for every form that we get requires WAY too much of our time.This is from the VBA help file - remember to press F1 from within the VB editor:
Quote Example As it applies to the SELECTION object.
This example copies the contents of the selection into a new document.
If Selection.Type = wdSelectionNormal Then Selection.Copy Documents.Add.Content.Paste End If As it appllies to the BookMark object.
This example sets the Book2 bookmark to the location marked by the Book1 bookmark.
ActiveDocument.Bookmarks("Book1").Copy Name:="Book2" As it applies to the Range object.
This example sets the Selection bookmark to the \Sel predefined bookmark in the active document.
ActiveDocument.Bookmarks("\Sel").Copy Name:="Selection" This example copies the first paragraph in the active document and pastes it at the end of the document.
ActiveDocument.Paragraphs(1).Range.Copy Set myRange = ActiveDocument.Range _ (Start:=ActiveDocument.Content.End - 1, _ End:=ActiveDocument.Content.End - 1) myRange.Paste This example copies the comments in the active document to the Clipboard.
If ActiveDocument.Comments.Count >= 1 Then ActiveDocument.StoryRanges(wdCommentsStory).Copy End If
You may also want to read the help files on protecting/unprotecting documents.
Incidentally if you have Office Pro, then you should be able to use InfoPath, which is a much better tool for this job.I've never heard of infopath, but I'm sure I could figure it out on my own pretty quickly; could you provide a brief explanation? (or a link to an good source of entry-level info; I googled it but it turned up general information & not-quite-newbie style info.)
As for the selection object - that accomplishes nothing. I tried to explain this in my post without being too verbose, but I guess I was too vauge...srry. I know how to use the copy command to put items on the clipboard, but (as far as I can tell) the object only works on data that physically exists within a document. You can copy plain, cells, columns, database FIELDS, and the like using the '.copy' command. This poses a problem for me because the data I want to place on the clipboard doesn't physically exist anywhere on the document, and cannot be placed (even temporarily) on the document because it has to be locked at all times. I have read the help file inside and out for the Copy command, as well as all related commands. The selection object serves me no good since it, like Copy, can only be used on physically existing information within a document. Something like:
Dim MyString As String MyString = "Hello World" MyString.Select Selection.Copy
Does not work. I've searched the help document for several keywords like "clipboard", "copystring", "strcopy", "stringcopy", & "str", but I keep turning up the same useless information... ...it's hard to search for information on something that you don't even know the name of!You might try using the Clipboard class which has two methods (SetDataObject and GetDataObject)
SetDataObject is used to copy data to the clipboard. GetDataObject is used to retrieve data from the clipboard.
Don't know if this works in VBA, but it's all the rage in VB.
Clipboard
Good luck. 8-)
|