Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004

    Question Unanswered: *Done* Information from Access textbox to an open excel file.


    I'v got a excel form (no specific name, 'couse it changes)
    Got a form with some information in some textboxe's ..

    How do I get access to send the info from txt1 to A5 on a preopend don't know the name of excel file?

    It's the only excel file open!!

    Should be possible to send to active or something.

    Please help out... I'm stuck!!

    Last edited by theJedi; 12-28-04 at 14:27.

  2. #2
    Join Date
    Sep 2004


    After hours of looking around I finaly solved it...

    Just incase someone else should ever need it here it is.....
    __________________________________________________ ______________

    ' Declare necessary API routines:
    Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As Long) As Long

    Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    Sub GetExcel()
    Dim MyXL As Object ' Variable to hold reference
    ' to Microsoft Excel.
    Dim ExcelWasNotRunning As Boolean ' Flag for final release.

    ' Test to see if there is a copy of Microsoft Excel already running.
    On Error Resume Next ' Defer error trapping.
    ' Getobject function called without the first argument returns a
    ' reference to an instance of the application. If the application isn't
    ' running, an error occurs.
    Set MyXL = GetObject(, "Excel.Application")
    If Err.Number <> 0 Then ExcelWasNotRunning = True
    Err.Clear ' Clear Err object in case error occurred.

    ' Check for Microsoft Excel. If Microsoft Excel is running,
    ' enter it into the Running Object table.

    ' Show Microsoft Excel through its Application property. Then
    ' show the actual window containing the file using the Windows
    ' collection of the MyXL object reference.
    MyXL.Application.Visible = True
    MyXL.Parent.Windows(1).Visible = True

    'Do manipulations of your file here.

    MyXL.ActiveCell.FormulaR1C1 = "What ever text you want"

    ' ...
    ' If this copy of Microsoft Excel was not running when you
    ' started, close it using the Application property's Quit method.
    ' Note that when you try to quit Microsoft Excel, the
    ' title bar blinks and a message is displayed asking if you
    ' want to save any loaded files.
    If ExcelWasNotRunning = True Then
    End If

    Set MyXL = Nothing ' Release reference to the
    ' application and spreadsheet.
    End Sub

    Sub DetectExcel()
    ' Procedure dectects a running Excel and registers it.
    Const WM_USER = 1024
    Dim hWnd As Long
    ' If Excel is running this API call returns its handle.
    hWnd = FindWindow("XLMAIN", 0)
    If hWnd = 0 Then ' 0 means Excel not running.
    Exit Sub
    ' Excel is running so use the SendMessage API
    ' function to enter it in the Running Object Table.
    SendMessage hWnd, WM_USER + 18, 0, 0
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts