Send form data to a Excel template

sonny

Registered User.
Local time
Yesterday, 19:21
Joined
Mar 2, 2004
Messages
140
I read a bunch of posts from this site and another and am tring to put the code below together.
Has anyone else done something simular to this. I could use a example. What I have so far are bits and pieces of other posts....

Code:
Public Function MSExcelOpen()
    Screen.MousePointer = vbHourglass

    On Error Resume Next
    gboolRunning = True

    'See if Excel is already running
    Set goExcel = GetObject(, "Excel.Application")
    If goExcel Is Nothing Then
        'If Excel was not running start a new instance
        Set goExcel = CreateObject("Excel.Application")
        'Set goExcel = New Excel.Application
        gboolRunning = False
    End If

    If goExcel Is Nothing Then
        MsgBox "Can't Open Excel"
        MSExcelOpen = False
    Else
        If Not goExcel.Visible Then
            goExcel.Visible = True
        End If
    End If
    MSExcelOpen = True

    DoEvents
    Screen.MousePointer = vbDefault
End Function




Public Sub ExcelFillCells()
    Screen.MousePointer = vbHourglass
    On Error GoTo ErrorHandler
    
    'code to make sure that all fields on the form are filled out
    If IsNull(Me.BCD_No) Or (Me.Amount) Or (Me.Assigned_To) Or (Me.Desc) Then
            Select Case MsgBox("All Fields Are Required In Order To Insert Create Your Cover Sheets!" & vbCr & vbCr & _
                               " Click ""YES"" To Go Back And Enter The Required Information." & vbCr & vbCr & _
                               " Click ""NO"" To Cancel.", vbCritical + vbYesNo)

            Case vbYes
                '// Return to the record.
                Me.Assigned_To.SetFocus
                GoTo ErrorHandler
            Case vbNo
                '// Cancel the sub.
                Exit Sub
            End Select
    If MSExcelOpen() Then
        
        'code to look for the Excel template file on the LAN
        Dim filepath As String
        filepath = "C:\*.xls"   'actual path will be determined later
    If Len(Dir(filepath, vbDirectory)) > 0 Then
        'if found open it
        'Code to open the file
       
      Else  'otherwise do a message saying cant find the file
        MsgBox ("Can't find the template file!")
        Exit Sub:
      End If
        'code to make a certain sheet active
        With goExcell.ActiveSheet
            'put the forms text box values into the cells

            .Cell(1, 1).Value = "Me.textBox1"
            .Cell(1, 2).Value = "Me.textBox2"
            .Cell(1, 3).Value = "Me.textBox3"
            .Cell(1, 4).Value = "Me.textBox4"
            .Cell(1, 5).Value = "Me.textBox5"
            .Cell(1, 6).Value = "Me.textBox6"
            .Cell(1, 7).Value = "Me.textBox7"

        End With
       End If
      End If
    Screen.MousePointer = vbDefault

    Exit Sub

ErrorHandler:
    MsgBox Err.Description
    Exit Sub
End Sub
 

Users who are viewing this thread

Back
Top Bottom