|
A trick that may work for you is to always name your text file with the
extension .CSV Excel is (usually) installed as the application associated
with this file type and will automatically fire up and import it. Try it
out by just double-clicking a .CSV file in Explorer.
You can then simply call the Win95 shell specifying your .CSV file as the
"program" to execute.
I used this technique in a VBA application after overcoming the fact that
the VBA help documentation lies about the built-in Shell function. To use
my trick from VBA you need to invoke the Windows ShellExecute function.
Here's the code I used, derived from the Microsoft Knowledge Base article
that admits the VBA defieicency but provides this work-round. It *should*
be reasonably generic.
Brian.
Declare Function ShellExecute Lib "shell32.dll" Alias " _
ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Global Const SW_SHOWNORMAL = 1
Function StartDoc(DocName As String)
' Executes an external program by specifying a document of a type
' with which it is associated.
' The VBA Shell function can't do this, despite what the Help file says!
Dim hWnd As Long
On Error GoTo StartDoc_Error
hWnd = 0
StartDoc = ShellExecute(hWnd, "Open" & Chr(0), DocName & Chr(0), "" &
Chr(0), "C:\" & Chr(0), SW_SHOWNORMAL)
Exit Function
StartDoc_Error:
MsgBox "Error reported by StartDoc: " & Err & " " & Error()
Exit Function
End Function
|