Copying from access to excel cells

I have a piece of code for copying from access to an excel cell but i only know how to copy text.  I want to copy the content of an access text box named txt1 to cell K2 -  what must i change to make it work.  Tried a few different syntax solutions but all fail.

Option Compare Database
Private Sub Command0_Click()
    Dim appExcel As Excel.Application
    Dim wbook As Excel.Workbook
    Dim wsheet As Excel.Worksheet

    Set appExcel = New Excel.Application
    appExcel.Visible = False
    Set wbook = appExcel.Workbooks.Open("C:\Users\Alan\Documents\alanstest.xls")
    Set wsheet = wbook.Worksheets("SCR")
    With wsheet
        .Range("K2").Value = "Paste Me"
    End With
    Set wsheet = Nothing
    wbook.Close True
    Set wbook = Nothing
    Set appExcel = Nothing    
End Sub
SweetingAAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Commented:

Option Compare Database
Private Sub Command0_Click()
    Dim appExcel As object
    Dim wsheet As Object

    Set appExcel = createobject("Excel.Application")
    appExcel.Visible = False
    Set wsheet = appExcel.Workbooks.Open("C:\Users\Alan\Documents\alanstest.xls").Worksheets("SCR")
   
    With wsheet
        .Range("K2").Value = Me.txt1
    End With
    wsheet.application.activeworkbook.save
    wsheet.application.activeworkbook.Close
   
    appExcel.quit  
    Set wsheet = Nothing  
End Sub
0
 
Rey Obrero (Capricorn1)Commented:


    With wsheet
        .Range("K2").Value = Me.txt1
    End With
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.