Import Excel values into a form

W

whylite

I am wanting to import some values from an excel spreadsheet to put into a
custom made form. This is what I have so far. I also need to run a couple
of if statements so that in the event of an error the function is aborted. I
wrote the script in excel for another file and have tried to modify it for
this application.

Function CommandButton1_Click()

Dim wellname
Dim fieldticket
Dim toolrun
Dim uwi
Dim lost_time
Dim total_rig
Dim crew
Dim stotal
Dim fname
Dim fdepth
Dim rig
Dim Path


Const iTitle = "Import DR Data File" ' title of dialog box
Const FilterList = "Microsoft Excel Workbook (*.xls),*.xls"
Path = Application.GetSaveAsFilename(savefilename, FilterList, , iTitle,
vbOKCancel)

If Path = "False" Then
Exit Sub
End If


Application.Workbooks.Open Path
If ActiveSheet.Range("AA1").Value <> "DR Data File" Then
MsgBox "Workbook is not a valid DR Data File!", vbCritical, "Import Data
File Error!"
Exit Sub
End If

wellname = ActiveSheet.Range("B44")
fieldticket = ActiveSheet.Range("A2")
toolrun = ActiveSheet.Range("B71")
uwi = ActiveSheet.Range("B45")
lost_time = ActiveSheet.Range("B235")
total_rig = ActiveSheet.Range("B237")
crew = ActiveSheet.Range("b203") & " / " & ActiveSheet.Range("b206") & "
/ " & ActiveSheet.Range("B209")
If ActiveSheet.Range("B212") <> "" Then
crew = ActiveSheet.Range("b203") & " / " & ActiveSheet.Range("b206") & "
/ " & ActiveSheet.Range("B209") & " / " & ActiveSheet.Range("B212")
End If
crew = StrConv(crew, vbProperCase)
stotal = ActiveSheet.Range("A3")
fname = ActiveSheet.Range("B50")
fdepth = ActiveSheet.Range("B73")
rig = ActiveSheet.Range("B70")

ActiveWorkbook.Close False

Item.UserProperties("Well Name").Value = wellname
Item.UserProperties("Field Ticket Number").Value = fieldticket
Item.UserProperties("NUMOFRUNS").Value = toolrun
Item.UserProperties("UWI").Value = uwi
Item.UserProperties("LT").Value = lost_time
Item.UserProperties("OT").Value = total_rig
Item.UserProperties("CREW").Value = crew
Item.UserProperties("REVENUE EST").Value = stotal
Item.UserProperties("Field").Value = fname
Item.UserProperties("WellDepth").Value = fdepth
Item.UserProperties("RigName").Value = rig


End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top