+ Reply to Thread
Results 1 to 6 of 6

VBA code working in Outlook 2010 but not in 2013

Hybrid View

  1. #1
    Registered User
    Join Date
    09-22-2015
    Location
    Amsterdam
    MS-Off Ver
    MS Office 2013
    Posts
    5

    VBA code working in Outlook 2010 but not in 2013

    Hi All,

    My vba code is working in outlook 2010 but not in outlook 2013 unfortunately. I hope one of you is able to help me. Please let me know if you need any more information.

    The error starts at the following line of code:
             objItem = Mid(objItem, InStr(objItem, "#") + 1)
    Below is the full code:
    Private Sub CommandButton1_Click()
    If ListBox1.Value = "" Then
    Exit Sub
    End If
    If ListBox2.Value = "" Then
    Exit Sub
    End If
    
    Dim myNameSpace As Outlook.NameSpace
    Dim myInbox As Outlook.Folder
    Dim Inbehandeling As Outlook.Folder
    Dim Events As Outlook.Folder
    Dim objApp As Application
    Dim strTicket, strSubject As String
    Dim new_msg As MailItem
    Dim ns As Outlook.NameSpace
    Dim moveToFolder As Outlook.MAPIFolder
    Dim objItem As Outlook.MailItem
    Set myNameSpace = Application.GetNamespace("MAPI")
    Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
    Set ns = Application.GetNamespace("MAPI")
    Teamnaam = Me.ListBox1.Value
    Werkstroom = Me.ListBox2.Value
    '-------
    'Controle of barcode er is
       ' Default value in case # is not found in the subject line
         strTicket = "None"
        
       ' Grab the subject from the message
            For Each objItem In Application.ActiveExplorer.Selection
                If objItem.Subject Like "*KlntVrzknr*" Then
                     objItem.Subject = objItem.Subject
                Else
                     objItem.Subject = objItem.Subject & "---KlntVrzknr#" & Format(Date, "yyyymmdd") & Format(Time, "hhmmss") & "#"
            End If
            
    objItem.Categories = UserForm1.TextBox1.Text
    
    
    'mail verplaatsen
    Set Inbehandeling = myInbox.Folders("A. In behandeling")
    objItem.Move Inbehandeling
    
       ' See if it has a hash symbol in it
              ' Trim off leading stuff up to and including the hash symbol
             objItem = Mid(objItem, InStr(objItem, "#") + 1)
            
       ' Now find the trailing space after the ticket number and chop it off after that
             If InStr(objItem, "#") > 0 Then
                 strTicket = "PromiseIII_" & Left(objItem, InStr(objItem, "#") - 1)
             End If
    
    'event aanmaken
         Set Events = myInbox.Folders("D. Events")
         Set Myitem = Application.CreateItem(olMailItem)
         Myitem.Subject = strTicket & ";" & "14;" & Format(Date, "yyyymmdd") & Format(Time, "hhmmss") & ";" & Teamnaam & ";" & Werkstroom & ";"
         Set myCopiedItem = Myitem.Copy
         
         myCopiedItem.Move Events
    
        
    '--------wegschrijven event naar Access--------
     
     Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim NoOfRecords As Long
      'Open the .accdb form database to retrieve data
      Set db = OpenDatabase("\\Europe.Intranet\DFSNL\P\GD\014226\Applicaties\Mailbox\sourceAccess.accdb")
      'Define the first recordset
      Set rs = db.OpenRecordset("SELECT * FROM Events")
     
     
     ' open database
         Set db = OpenDatabase("\\Europe.Intranet\DFSNL\P\GD\014226\Applicaties\Mailbox\sourceAccess.accdb")
        ' open table as a recordset
        Set rs = db.OpenRecordset("SELECT * FROM Events")
        ' add a record to the recordset
        rs.AddNew
        ' fill fields with data ... in this case from cell A1
        rs.Fields("Events") = Myitem.Subject
        ' write back recordset to database
        rs.Update
        ' important! cleanup
        rs.Close
        ' forget to close the DB will leave the LDB lock file on the disk
        db.Close
    
        Set rs = Nothing
        Set db = Nothing
        
    '----------
    
    Unload UserForm1
    MsgBox ("Verzoek in behandeling genomen")
    
    Next
    End Sub
    Thanks in advance!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA code working in Outlook 2010 but not in 2013

    What's the error message?

    Do you have any items marked as MISSING when you goto Tools>References...?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-22-2015
    Location
    Amsterdam
    MS-Off Ver
    MS Office 2013
    Posts
    5

    Re: VBA code working in Outlook 2010 but not in 2013

    Thank you Norie for your quick reply.

    I get the following error message:
    Run-time error "438": Object doesn't support this property or method.
    I don't have any items marked as missing.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: VBA code working in Outlook 2010 but not in 2013

    What are you actually trying to do with that line of code?

    objItem is a mail item, are you trying to set the body of the email, the subject...?

  5. #5
    Registered User
    Join Date
    09-22-2015
    Location
    Amsterdam
    MS-Off Ver
    MS Office 2013
    Posts
    5

    Re: VBA code working in Outlook 2010 but not in 2013

    In the beginning of the code I'm adding a unique number to the subject. for example the subject of the email was: "Welcome to excelforum" and the code changes it to : "Welcome to excelforum #memberid 2321".

    At the code where the first error originates:
             objItem = Mid(objItem, InStr(objItem, "#") + 1)
    I'm looking if this email already received a unique number. If it has the subject of the e-mail has an "#" sign.

    If it doesnt have the "#" sign the position of the sign would be 0 and a new unique number is added. If it has a unique sign the number won't be added again.

    If InStr(objItem, "#") > 0 Then
                 strTicket = "PromiseIII_" & Left(objItem, InStr(objItem, "#") - 1)
             End If

  6. #6
    Registered User
    Join Date
    09-22-2015
    Location
    Amsterdam
    MS-Off Ver
    MS Office 2013
    Posts
    5

    Re: VBA code working in Outlook 2010 but not in 2013

    I found a solution to my problem by just trying different things :D

    I don't know if this is the cleanest solution, but hey it works!

    I created an extra variable as a string, which I use to assign the position of the # sign instead of ObjItem which was from the type of Outlook.Mailitem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code working in Outlook 2010 but not in 2013
    By fiffers in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 09-22-2015, 05:16 AM
  2. Macros 2010 Not working in Excel 2013
    By waqarqrl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2015, 03:57 AM
  3. VBA working in Excel 2013 but not 2010
    By sb2323 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2015, 07:26 AM
  4. Code works for outlook 2010 but not 2013
    By Legend Rubber in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2015, 05:00 PM
  5. Macro code working fine in excel 2013 but not in excel 2010.
    By sere in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-10-2014, 02:23 AM
  6. Macro from 2010 not working correctly in 2013
    By Phixer in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-26-2014, 12:24 PM
  7. VBA Working in Excel 2010 and not 2013
    By Jason*** in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-04-2014, 11:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1