1. Here's a thread that needs an answer: DataNumen Outlook Repair

Combo Box

Discussion in 'Using Outlook' started by LMS, Jan 26, 2013.

  1. Diane Poremsky

    Diane Poremsky

    Senior Member
    In the VBA editor, place the cursor in the line, right click > Toggle > Breakpoint. The macro will stop when it gets to that point.
  2. LMS

    LMS

    Senior Member
    I did it and here is what I learned and perhaps you now have an idea...

    I created the breakpoint for the first line......

    When I open the contact directly from the folder and click on macro to open the combobox from the macro and relate userform, the VBA Editor shows up immediately, the first line is yellow....then I keep clicking on F8 and it yellows different lines one after another, and then goes to the userform related to the module, and it does the same...and then it eventially will open up the combobox......

    When I open the contact from the shortcut, it and click on macro to open the combobox from the macro and relate userform, the VBA Editor shows up immediately, the first line is yellow....then I keep clicking on F8 and it yellows different lines one after another, but will not go to the userform relate and will not open up the combobox....

    So do you have any thoughts to fix it now?
  3. Diane Poremsky

    Diane Poremsky

    Senior Member
    That goes back to my friend telling me there were problems running code when items are opened using shortcuts and why I suggested changing Private to Public. The macro has no problems with everything in it's code but it can't "see" outside of the current module.
  4. LMS

    LMS

    Senior Member
    thanks very much as usual...as it is not my expertise!

    you wrote the following to change to public before and I did it, but it did not fix it...any other thoughts?

    Private Sub UserForm_Initialize()

    and

    Private Sub CommandButton5_Click()
  5. Diane Poremsky

    Diane Poremsky

    Senior Member
    I'm out of ideas. Sorry.
  6. LMS

    LMS

    Senior Member
    I appreciate your time as usual and if anything else hits your head, feel free to let me know, and if something else comes up, I will let you know as well.
  7. LMS

    LMS

    Senior Member
    One more area for you to see and let me know if you have a thought. You can can see earlier in this thread, the userform and related module codes, an there what happen when I run thru the breakpoint:

    When I open the contact from the folder, and there is the breakpoint as I created it, the first line shows up as yellow, and then when I keep clicking on F8, the following lines show up yellow in the following order of lines going down:

    If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then

    Set oContact = GetCurrentItem()

    Function GetCurrentItem() As Object

    Set objApp = Application

    On Error Resume Next

    Select Case TypeName(objApp.ActiveWindow)

    Case "Explorer"

    Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)

    End Select

    Set objApp = Nothing

    End Function

    And then goes up to the following line in yellow:

    UserForm10.Show

    And then it goes to the Userform10, and yellows the lines going down:

    Public Sub UserForm_Initialize()

    With ComboBox16

    .AddItem "Marketing Intro E-mail to GHP Contacts"

    .AddItem "Follow-Up From Meeting at GHP Event"

    End With

    End Sub

    And then it opens up the Combobox with the related CommandButton

    And when I open the contact from the shortcut, from the module line, it does not got to each line as I mentioned above, it yellows the first line and then goes in the following order:

    If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then

    End If

    Set oMail = Nothing

    End Sub

    And then it opens up the Userform10 in the Visual Basic Editor and not the Combobox and related CommandButton.

    So is there a way to fix this so that when you open the contact from the shortcut, it goes thru the same process of opening up the Combobox and related CommandButton?
  8. LMS

    LMS

    Senior Member
    Per the above, I got a comment from another forum stating:

    "Your code says if the first selected item in your folder is a contact item then go on and do all the stuff that's within the If-Then block.

    In other words, if that If-condition is not true, then you don't have a contact item selected."

    If this is the case, any idea how to adjust the code so that if the first selected item is the shortcut to the contact, then the contact from the shortcut is the contact item to get things going?

    Would be a great answer if you agree with what was said and have an idea!!!
  9. Diane Poremsky

    Diane Poremsky

    Senior Member
    You have a contact open - because it was opened from a shortcut it may not have true focus. You can comment out that line and the end if and see if it works. Or... between these two lines:

    End With

    End If

    add

    Else

    msgbox "what is this?"

    and see if it works. If it sees the item the contact was attached it, it will error because the fields the macro needs are not available.

    The reason for adding that line is so the code doesn't error if you accidently run it when you have something else selected.
  10. Diane Poremsky

    Diane Poremsky

    Senior Member
    The reason for adding the If line is so it doesn't error.... but it will work without that line. Add

    on error resume next

    above the if line so it ends cleanly if it errors.
  11. LMS

    LMS

    Senior Member
    Thank you for your time very much. I am not good at typing in certain areas as not clear to me. So here is the code of the module, and can you add the words in the right places (and show them a bold) and then I can the right words to the right place. When i deleted the first line, it did not solve the problem. thanks much!!!

    Public lstNum10 As Long

    Public Sub Marketing_GHP_Contacts()

    Dim oMail As Outlook.MailItem

    Dim oContact As Outlook.ContactItem

    If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then

    Set oContact = GetCurrentItem()

    Dim strTemplate As String

    UserForm10.Show

    Select Case lstNum10

    Case -1

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler and Vcard.oft")

    Case 0

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Marketing Initial E-mail to GHP Contacts.oft")

    Case 1

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Follow-Up From Meeting at GHP Event.oft")



    End Select

    Set oMail = Application.CreateItemFromTemplate(strTemplate)

    With oMail

    .To = oContact.Email1Address

    .Display

    End With

    End If

    Set oMail = Nothing

    End Sub

    Function GetCurrentItem() As Object

    Dim objApp As Outlook.Application



    Set objApp = Application

    On Error Resume Next

    Select Case TypeName(objApp.ActiveWindow)

    Case "Explorer"

    Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)

    Case "Inspector"

    Set GetCurrentItem = objApp.ActiveInspector.CurrentItem

    End Select



    Set objApp = Nothing

    End Function
  12. Diane Poremsky

    Diane Poremsky

    Senior Member
    Delete or comment out (add a ' at the beginning of the line so it turns green) to the two bolded lines in the original code. Add the error handler so it's less annoying if you select the wrong type of item.

    On Error Resume NextIf TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then

    Set oContact = GetCurrentItem()

    Dim strTemplate As String

    UserForm10.Show

    Select Case lstNum10

    Case -1

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler and Vcard.oft")

    Case 0

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Marketing Initial E-mail to GHP Contacts.oft")

    Case 1

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Follow-Up From Meeting at GHP Event.oft")

    End Select

    Set oMail = Application.CreateItemFromTemplate(strTemplate)

    With oMail

    .To = oContact.Email1Address

    .Display

    End With

    End If
  13. LMS

    LMS

    Senior Member
    So this is the only line to adjust this way??

    On Error Resume NextIf TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then

    - - - Updated - - -

    And I don't understand what you mean by

    "Delete or comment out (add a ' at the beginning of the line so it turns green) to the two bolded lines in the original code."

    What lines am I supposed to delete please?
  14. Diane Poremsky

    Diane Poremsky

    Senior Member
    That was screwed up when i bolded it - the lines merged . :( You need to delete or comment the End If too.

    On Error Resume Next

    ' If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then

    ' End If

    Your code should look like this - (but with more code in between the userform and the end if)

    03.01.2013-14.24.png
  15. LMS

    LMS

    Senior Member
    So is this what it should look like please?

    On Error Resume Next

    If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then

    Set oContact = GetCurrentItem()

    Dim strTemplate As String

    UserForm10.Show

    Select Case lstNum10

    Case -1

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler and Vcard.oft")

    Case 0

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\Marketing Initial E-mail to GHP Contacts.oft")

    Case 1

    strTemplate = ("C:\Users\Stoler Law\AppData\Roaming\Microsoft\Templates\E-mail From Lou Stoler - Follow-Up From Meeting at GHP Event.oft")

    End Select

    Set oMail = Application.CreateItemFromTemplate(strTemplate)

    With oMail

    .To = oContact.Email1Address

    .Display

    End With
  16. LMS

    LMS

    Senior Member
    I did the forgoing and an error showed up since I deleted End If......and then when I put in back and above it added the On Error Resume Next, it does not work from the contact opening thru the shortcut.

    Any other thoughts?
  17. Diane Poremsky

    Diane Poremsky

    Senior Member
    You need to delete the if line.

    If TypeName(ActiveExplorer.Selection.Item(1)) = "ContactItem" Then

    and the

    End If
  18. LMS

    LMS

    Senior Member
    YOU ARE STILL THE BEST!!!!!

    I deleted them both and when I open up the contact from the shortcut under the calendar, the macro works perfectly!!!

    Thanks so so much!!

Share This Page