Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to copy values from outlook form into excel

Status
Not open for further replies.

jahlmer

Technical User
Aug 23, 2000
143
US
Ok, nobody in the office forum has responded, so I am taking my chances in here.

I have tried many different codes that I have found on tek-tips, as well as google groups, and the help files, and microsoft MSDN. After 3 days I can't find anything to make this work properly.

I need an outlook contact form to have a button or control to open an excel spreadsheet and copy data to the pre-formatted excel form (cannot do bulk export). I've customized the outlook contact form with a cmd1 button, but the following code that I place into the form says line 2 has a problem. I am one hair away from pulling all my hair out.

Sub cmd1_click()
Dim oOL As Outlook.Application
Dim oInspector As Outlook.Inspector
Dim val1, val2 As String
Dim oContact As Outlook.ContactItem
Set oOL = CreateObject("Outlook.Application")
' the item must be open for this to work
Set oInspector = oOL.ActiveInspector
Set oContact = oInspector.CurrentItem
val1 = oContact.UserProperties("Company").Value
val2 = oContact.UserProperties("FullName").Value

Set oExcel = Item.Application.CreateObject("Excel.Application")
oExcel.Workbooks.open("C:\forms\oeform.xls")
oExcel.Visible = True
'oExcel.Workbooks.Add
Set oSheet = oExcel.Workbooks(1).Worksheets(1)
oSheet.Activate
Set oCellData = oSheet.Range("A3")
oCellDat.Value = val1
Set oCellData = oSheet.Range("D10")
oCellDat.Value = val2

End Sub

There has got to be a better way to do this. What I've found is the most promising yet doesn't work. I am a novice coder.

Any help will be greatly appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top