[AccessD] Losing 3ms on date insert?

Stuart McLachlan stuart at lexacorp.com.pg
Mon Nov 26 23:47:22 CST 2018


In answer to your question: Yes. 

But I don't see how your link relates to that.  OLE is a different beasst to passing data to and 
from a spreadsheet.

Here's an example of controlling a spreadsheet from another application (which could easily 
be a service).


#COMPILER PBWIN 10
#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "Excel.inc"

'------------------------------------------------------------------------------
' Main application entry point...
'
FUNCTION PBMAIN
  DIM oExcelApp       AS Excel_Application
  DIM oExcelWorkbook  AS Excel_Workbook
  DIM oExcelWorkSheet AS Excel_WorkSheet

  DIM vBool    AS VARIANT
  DIM vText1   AS VARIANT
  DIM vText2   AS VARIANT
  DIM vFile    AS VARIANT
  DIM vFileFmt AS VARIANT
  DIM oVnt     AS VARIANT
  DIM nVnt     AS VARIANT
  DIM vX       AS VARIANT
  DIM vY       AS VARIANT
  DIM x        AS LONG
  DIM y        AS LONG
  DIM ws       AS WSTRING

  ' Open an instance of EXCEL
  oExcelApp = ANYCOM $PROGID_Excel_Application

  ' Could EXCEL be opened? If not, terminate this app
  IF ISFALSE ISOBJECT(oExcelApp) OR ERR THEN
    MSGBOX "Excel could not be opened. Please check that Excel and VBA are installed."
    EXIT FUNCTION
  END IF

  ' Make MSEXCEL visible
  vBool = 1
  OBJECT LET oExcelApp.Visible = vBool

  ' Create a new workbook in EXCEL
  OBJECT CALL oExcelApp.WorkBooks.Add TO oExcelWorkBook
  IF ISFALSE ISOBJECT(oExcelWorkbook) OR ERR THEN
    MSGBOX "Excel could not open a new workbook. Please check that VBA is installed."
    GOTO Terminate
  END IF

  ' Create a new worksheet in the workbook and use this
  ' worksheet reference to pump data into EXCEL
  OBJECT CALL oExcelWorkBook.WorkSheets.Add TO oExcelWorkSheet
  IF ISFALSE ISOBJECT(oExcelWorkSheet) OR ERR THEN
    MSGBOX "Excel could not open a new worksheet. Please check that VBA is installed."
    GOTO Terminate
  END IF

  FOR y = 1 TO 50
    FOR x = 1 TO 5
      vX = x
      vY = y
      ws = "Cell " & CHR$$(x + 64) & FORMAT$(y)
       vText1 = ws
      OBJECT LET oExcelWorkSheet.Cells.Item(vY, vX) = vText1
    NEXT x

     vX = 6
     nVnt = y + y / 10
    OBJECT LET oExcelWorkSheet.Cells.Item(vY, vX) = nVnt

   vX = 7
    ws = FORMAT$(RND(-1000,1000), "$#,.00")
    vText2 = ws
    OBJECT LET oExcelWorkSheet.Cells.Item(vY, vX) = vText2
  NEXT y

  OBJECT CALL oExcelWorksheet.PrintPreview

  ' Save the new XLS document to disk
  vFile = "Test.xls"$$
  OBJECT CALL oExcelWorkBook.SaveAs(vFile)
    '----------------------------------------------------------------

Terminate:
  MSGBOX "Press the OK button to close Excel and exit the application"

  ' Close the current document and then close EXCEL completely
  OBJECT CALL oExcelApp.ActiveWindow.Close
  OBJECT CALL oExcelApp.Quit

  ' Release the interfaces.  We could omit this since the
  ' app is about to close, but "best practice" states we
  ' should clean our house before moving out.
  SET oExcelApp       = NOTHING
  SET oExcelWorkbook  = NOTHING
  SET oExcelWorkSheet = NOTHING

END FUNCTION 


On 26 Nov 2018 at 22:32, Jim Lawrence wrote:

> Can an external service be attached to an excel spreadsheet in which
> parameters can be pasted back and forth?
> 
> Like:
> 
> https://support.office.com/en-us/article/insert-an-object-in-your-exce
> l-spreadsheet-e73867b2-2988-4116-8d85-f5769ea435ba
> http://bit.ly/2P5iUDh
> 
> Jim 
> 



More information about the AccessD mailing list