• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Copy text to Windows clipboard

Community Beginner ,
Jul 03, 2019 Jul 03, 2019

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!

TOPICS
Scripting

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 05, 2019 Jul 05, 2019

mHm, I have a Script where I do this:

  • Compose a file path and copy it to the clipboard (see function below).
  • Instruct the user with this note: «The bibliographic application Citavi will be started. … Select the RTF file to be handled (paste the file-name from the clipboard) …»
  • Start the bibliographic application and wait for it's completion …

Obviously this only be done from the Windows clipboard contents. It works as intended.

function CopyToClipboard (theString) { //=== Copy string to clipboard ===

...

Votes

Translate

Translate
Enthusiast ,
Jul 03, 2019 Jul 03, 2019

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:

  • FrameMaker Interchange Format;
  • Rich Text Format;
  • Text;
  • Unicode Text;
  • FrameMaker Interchange Format (Unicode).

However if the selection is a text frame the options will be:

  • Metafile;
  • Enhanced Metafile.

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

In Visual Basic this should paste the required formats:

Clipboard.GetData(DataFormats.Text)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2019 Jul 05, 2019

Copy link to clipboard

Copied

mHm, I have a Script where I do this:

  • Compose a file path and copy it to the clipboard (see function below).
  • Instruct the user with this note: «The bibliographic application Citavi will be started. … Select the RTF file to be handled (paste the file-name from the clipboard) …»
  • Start the bibliographic application and wait for it's completion …

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 08, 2019 Jul 08, 2019

Copy link to clipboard

Copied

LATEST

Thanks K.Daube​, this worked perfectly. Thanks frameexpert​ and Ian Proudfoot​ for your suggestions!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2019 Jul 03, 2019

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines