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. I've customized the form with a cmd1 button, but the following code 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!
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. I've customized the form with a cmd1 button, but the following code 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"
val2 = oContact.UserProperties("FullName"
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!