Paste OLE Object dialog settings

I am trying to use the .sendcommand key-in "clipboard paste" from a vba to embed a selected portion of a temporary excel spreadsheet into a MicroStation model and it seemed to be working fine. However I've found that if settings within the Paste OLE Object dialog have been changed from Paste as: Embedded, Method: By Size, the command won't run correctly. How can I specify the correct settings before I run the command? I don't see any documentation or anything in user preferences to do this.

Help is appreciated,

Stephanie

Parents
  • Typically my next step would be to see if the VBA macro recorder could identify any usable access strings you could get/set via CExpression.  However this dialog does not provide any access strings for use.  There is an "OLECNTR PASTEMETHOD" keyin that should allow you to set the paste method using either ("ByObjectSize" or "By2CornerPoints") as an argument although I do not see either method activating as one would expect.

    HTH,

    Bob



  • Hi Bob,

    Thanks for the quick response. That looks promising. Unfortunately when I tried implementing the "copy paste" command, it appears to paste the clipboard contents (a range of cells from an Excel file)  as textnodes without any of the spreadsheet formatting. If I do a manual copy to the clipboard and then use the edit paste command from MicroStation it looks like a table. Do you know how I would do this programmatically? After I get there, I can try the keyin you suggested.

    Stephanie

  • Sorry, there is no convenient API available.  You also may want to consider an alternate workflow because the OLE object pasted in this way provides only a "formatted" picture, vs. usable vector (linked) graphics like DDE Links copy/paste option provides (though no formatting).

    If you want more control and being able to dynamically update the image, consider having VBA code in Excel to export the Excel selection as a picture to either a network share, or local if the spreadsheet is local.  Then in MicroStation create a Raster Reference attachment and position the exported Excel image to a known/common location.  Using this workflow your design files would never need to be manually or programmatically updated, since they would always be "current" to the exported image (with formatting) from Excel.

    If you want to use the OLE image in MicroStation from the clipboard using the object's "By Size" setting, you will need to drive the MicroStation interface using DMSG keyins (code snip below).  You would have to change the action/sequence to initiate a "by corners" setting, but that could be done easily - by going "down" one item, then back "up".

    Sub TEST_ClipboardPasteExcelSelection()    ' Start clipboard paste command, verifying OLE object is present
        CadInputQueue.SendCommand "CLIPBOARD PASTE"
        If CommandState.CommandName <> "Paste OLE Object" Then
            MsgBox "OLE object not present in Clipboard. Exiting.."
            Exit Sub
        End If
       
        ' Work-around for OLECNTR PASTEMETHOD By2CornerPoints and ByObjectSize not operating.
        ' Method: "By Size" (a.k.a. ByObjectSize)
        CadInputQueue.SendCommand "DMSG FOCUSDIALOG -79"    ' Send Focus to ToolSettings
        CadInputQueue.SendCommand "DMSG CURSOR NEXTFIELD"   ' Tab key
        CadInputQueue.SendCommand "DMSG ACTION OKAY"        ' Enter key
        CadInputQueue.SendCommand "DMSG CURSOR LINEEND"     ' End key
        CadInputQueue.SendCommand "DMSG ACTION OKAY"        ' Enter key
       
        ' Coordinate to place (center of) clipboard object at.
        Dim ptCenter As Point3d: ptCenter = Point3dFromXYZ(0, 0, 0)
        CadInputQueue.SendDataPoint ptCenter
       
    End Sub

    HTH,
    Bob



    Answer Verified By: Stephanie Doherty 

  • Bob,

    I think your proposed workaround could do what I want, but how would I know (programmatically) what the current selections are in the Paste OLE Object dialog box, so that I only change them if needed?

    Thanks,

    Stephanie

Reply Children
No Data