Select to view content in your preferred language

Populate Textbox with excel cell value

1353
1
12-30-2010 10:53 AM
ColbyParnell
Emerging Contributor
Is this possible.

I can open the excel file i want to get the data from but im not sure how to get the corrisponding values into the user form.

Code i have to open excel via button click:
Private Sub OpenNewWarrant()
Dim VolDate As Date
Dim xlApp As Object    
    Set xlApp = CreateObject("excel.application")
    xlApp.Visible = True
    Set myfile = xlApp.Workbooks.Open("C:\AirPhoto\Test.xls") 'etc...
    Set xlApp = Nothing    ' the application, then release the reference.

End Sub


Im thinking something like this but obviously it needs to be tweaked...
 tb6.Value = myfile.Workbooks.ActiveSheet("C8").Value 
0 Kudos
1 Reply
ColbyParnell
Emerging Contributor
Ok so if i open the file and populate right away this works like a charm:
Private Sub CommandButton1_Click()
Dim xlApp As Object
Dim myfile As ExcelWorkspaceFactory


    Set xlApp = CreateObject("excel.application")
    xlApp.Visible = True

    Set myfile = xlApp.Workbooks.Open("C:\AirPhoto\Test.xls")
    tb6.Value = xlApp.ActiveWorkbook.Sheets("sheet1").Range("C8").Value


But if i change something in the cell and try to update it returns an error of: runtime error 91 Object variable or with block variable not set
0 Kudos