Copy link to clipboard
Copied
Is there a trick to copy text to the Windows clipboard?
I'm using doc.Copy(0) and I'm getting selected text into the clipboard but it only pastes into FrameMaker and not on Windows (outside of FM).
I need the text in the clipboard since I have a vba script that wants to read from its contents.
Thanks!
mHm, I have a Script where I do this:
Obviously this only be done from the Windows clipboard contents. It works as intended.
...function CopyToClipboard (theString) { //=== Copy string to clipboard ===
Copy link to clipboard
Copied
I tried this and I get the expected results for pasting into other applications. When you copy a selection to the clipboard, FrameMaker adds several versions to the clipboard. For a normal selection of text paragraphs you may find these formats:
However if the selection is a text frame the options will be:
One way to test the available clipboard formats is to copy the required text then manually select Edit > Paste Special. The dialog shows you what FrameMaker has on the clipboard.
I believe that FrameMaker is probably doing what is expected and the selection of the format to paste should be controlled by Visual Basic. It's so long since I touched VB that I can't really help with that.
Good luck
Ian
Copy link to clipboard
Copied
In Visual Basic this should paste the required formats:
Clipboard.GetData(DataFormats.Text)
Copy link to clipboard
Copied
mHm, I have a Script where I do this:
Obviously this only be done from the Windows clipboard contents. It works as intended.
function CopyToClipboard (theString) { //=== Copy string to clipboard =============================
// Arguments theString: string to be copied to clipboard
// Called by FMbiblioCallBibapp
// Reference Based on Rick Quatro's method
var oDoc, tRange, masterPage, textFrame, oPgf, textLoc, PT = 65536;
// Create a textframe with a paragraph on the first masterpage (which always exists)
tRange = new TextRange;
oDoc = app.ActiveDoc;
masterPage = oDoc.FirstMasterPageInDoc; // Get first master page in document.
textFrame = oDoc.NewTextFrame (masterPage.PageFrame); // Add a temporary text frame to the master page.
textFrame.Width = 480 * PT;
oPgf = textFrame.FirstPgf;
textLoc = new TextLoc (oPgf, 0);
oDoc.AddText (textLoc, theString); // write string into this paragraph
tRange.beg.obj = oPgf; // select this paragraph
tRange.beg.offset = 0;
tRange.end.obj = oPgf;
tRange.end.offset = theString.length;
oDoc.TextSelection = tRange;
oDoc.Copy (0); // copy selection to clipboard not interactive
textFrame.Delete (); // delete the text frame
} // --- end CopyToClipboard
Copy link to clipboard
Copied
Thanks K.Daube​, this worked perfectly. Thanks frameexpert​ and Ian Proudfoot​ for your suggestions!
Copy link to clipboard
Copied
Instead of using the clipboard, write the text to a file, then read the contents of the file with VB.