|
IDEA: Perhaps I should be using DDE commands to open MS Excel and use DDEpoke to try and populate cells in the spreadsheet and pass the GAMMAINV analysis through to Excel.
OBSERVATION: Unfortunately I'm having difficulty trying to figure out how DDE functions work before even attempting to modify the sample code to process a GAMMAINV instruction.
This is sample code that both compiles and runs without producing an error message and opening my little message box to let me know that the code ran through to completion, but I still don't think it is working correctly. It opens MS Excel without a problem, but does not appear to populate any cells with values (as observed by physically looking at the spreadsheet). Neither does MS Chart open and show me a graph.
My test code runs from a command button (Command0) placed on a blank form:
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
Dim intI As Integer, intChan1 As Integer
Dim strTopics As String, strResp As String, strSheetName As String
On Error Resume Next ' Set up error handling.
intChan1 = DDEInitiate("Excel", "System") ' Establish link.
If Err Then ' If error occurs, Excel may
Err = 0 ' not be running. Reset error
Shell "C:\Program Files\Microsoft Office\Office\Excel.exe", 1
' and start spreadsheet.
If Err Then Exit Sub ' If another error, exit.
' Establish Spreadsheet link.
intChan1 = DDEInitiate("Excel", "System")
End If
' Create new worksheet.
DDEExecute intChan1, "[New(1)]"
' Get topic list, worksheet name.
strTopics = DDERequest(intChan1, "Selection")
strSheetName = Left(strTopics, InStr(1, strTopics, "!") - 1)
' Terminate DDE link.
DDETerminate intChan1
' Establish link with new worksheet.
intChan1 = DDEInitiate("Excel", strSheetName)
For intI = 1 To 10 ' Put some values into
DDEPoke intChan1, "R1C" & intI, intI ' first row.
Next intI
' Make chart.
DDEExecute intChan1, "[Select(""R1C1:R1C10"")][New(2,2)]"
' Terminate all links.
DDETerminateAll
MsgBox "done"
Exit_Err_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Err_Command0_Click
End Sub
(EDIT: Sample code was copied from Microsoft Visual Basic Help files when looking at the EXAMPLE link from the DDERequest function description)
Last edited by ctaylor; 09-10-2003 at 12:18 PM.
|