What am I doing wrong?



  • 1. Macro to Delete Items on Command
    The following macro deletes items from my deleted folder that are older than two months. It used to mostly work. (It always errored out instead of just ending -- but that didn't bother me.) Now it errors right away with this error: "Object doesn't support this property or method" The error is on the line: If itmMailItems(x).ReceivedTime < DeleteDate Then What is suspicious is that there are 5849 items in my deleted folder. However, the macro is counting 6551. Or at least that's the value of the variable "x" when the error occurs. Any ideas on what's going on? Thanks. Dim objApplication As Outlook.Application Dim objNameSpace As Outlook.NameSpace Dim itmMailItems As Items Dim DeleteDate As Date ' Retention Date Dim x As Long DeleteDate = DateAdd("m", -2, Date) Set objApplication = CreateObject("Outlook.Application") Set objNameSpace = Application.GetNamespace("MAPI") Set itmMailItems = objNameSpace.GetDefaultFolder(olFolderDeletedItems).Items ' Loop through the deleted folder For x = itmMailItems.Count To 1 Step -1 If itmMailItems(x).ReceivedTime < DeleteDate Then itmMailItems.Remove (x) End If Next x ' Clean objects Set itmMailItems = Nothing Set objNameSpace = Nothing
  • 2. working with attachments
    My process that I need to automate involves emails with attachments. Through the people doing the job, the attachments, which are text files, become Xls and Doc files depending on which information they pertain to. It's not hard to differentiate. My problem is how can I open the text file directly into Word or Excel? Can I use the MailItem.Attachment collection with the corresponding number, because the attachments are usually 3 or 4 for each email, and append that to a document for word? ie. DocumentObject.Content.InsertAfter "" & Item.Attachment I haven't attempted pushing data into an excel spreadsheet yet, but I can only assume it's just as easy. and then once the text is in an excel spreadsheet, invoke another macro(probably recorded) to format the data into the nice and easy to read columns we've come to utilize. So far, I've been able to process the body of emails with their information. Push the body to word, save the file with a dynamicly created filename and path(even if the path doesn't exist), and close the document, but not shut down word. Causes a runtime error. I believe it was 496 error number? Sorry, I'm spacing out on that. Thanks for any help.
  • 3. Auto saving attachment to network directory
    Hi everyone. I'm not sure if Outlook does not have this ability out of the box but I have the following situation I need to address: I have an email being sent a specific email account that has existing server side rules that redirect the email. This email account is setup to be used by an application for distributing reports. Along with the redirect of the email, I need it to automatically save the attached report to a network drive. It will need to create the directory i.e. "Reporting Date Jan 1 2006" so each days reports are in a specific directory. The attachment needs to remain as part of the email and redirected. I just need to save off an archived copy for future retreival. Is this possible with Outlook out of the box? We have Outlook 2003. If not, how can I do this? It will have to be done using the existing product functionality as I would never get approval to buy any third party plug in. Thanks.
  • 4. Schemas and DASL for AdvancedSearch
    How can I find the proper syntax and schema references to various outlook fields to use to make a DASL filter for AdvancedSearch? Help has not been very helpful and talks about DASL without any reference to how to write it! Even searching MSDN has yielded limited results and nothing that helps me. Specifically: I want to be able to reference a filter to search all text (e.g. subject and message) contained in documents within a folder. -- - K Dales
  • 5. Documentation about duplicates
    Where would I find programming documentation how Outlook defines what duplicates are? My goal is to synchronize the PST files between two laptops. However, I need to have a clear idea how Outlook handles duplicates. This would also include how Outlook handles the items in the Activities tab. Your feedback is appreciated.

What am I doing wrong?

Postby Lanceford » Thu, 07 Dec 2006 04:41:52 GMT

I am using outlook 2003 and want to Auto BCC each message that is sent.

Looking at outlook, I select Alt F11 to open the VB tool

Under Microsoft Office Outlook Objects, I select ThisOutlookSession

Then in the window that opens, I place the script below.

Then I select Save, close VB and Outlook, then re-open

When I try to send a new message I get a "Beep" like something sent back an 
error along with a blank message.  But the BCC never puts the address in the 
BCC field, on or after sending.

What am I doing wrong?

Thanks in Advance!

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objRecip As Recipient
    Dim strMsg As String
    Dim res As Integer
    Dim strBcc as String

    ' #### USER OPTIONS ####
    ' address for Bcc -- must be SMTP address or resolvable
    ' to a name in the address book
    strBcc = " XXXX@XXXXX.COM "

    On Error Resume Next
    Set objRecip = Item.Recipients.Add(strBcc)
    ' handle case of user canceling Outlook security dialog
    If Err = 287 Then
        strMsg = "Could not add a Bcc recipient " & _
          "because the user said No to the security prompt." & _
          " Do you want still to send the message?"
        res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                "Security Prompt Cancelled")
        If res = vbNo Then
            Cancel = True
        End If
        objRecip.Type = olBCC
        If Not objRecip.Resolved Then
            strMsg = "Could not resolve the Bcc recipient. " & _
              "Do you want still to send the message?"
            res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                    "Could Not Resolve Bcc Recipient")
            If res = vbNo Then
                Cancel = True
            End If
        End If
    End If

    Set objRecip = Nothing
End Sub

Re: What am I doing wrong?

Postby Sue Mosher [MVP-Outlook] » Thu, 07 Dec 2006 06:10:53 GMT

Did you check the basics like macro security? See  http://www.**--****.com/ 

Sue Mosher, Outlook MVP
   Author of Configuring Microsoft Outlook 2003
   and Microsoft Outlook Programming - Jumpstart for 
     Administrators, Power Users, and Developers

Re: What am I doing wrong?

Postby Lanceford » Thu, 07 Dec 2006 06:22:18 GMT

Aaahhh... No.  That's it!  :D

You are my hero, Sue.

Did you check the basics like macro security? See 

Sue Mosher, Outlook MVP
   Author of Configuring Microsoft Outlook 2003
   and Microsoft Outlook Programming - Jumpstart for
     Administrators, Power Users, and Developers

Similar Threads:

1.Using Bookmarks in Word documents - what am I doing wrong

2.What am i doing wrong?[simple word automation C# 05]

3.whether am i doing wrong?


I have dot file with two pages (VBA code embeded in it)
1st page: it will have company name and client name (bookmarks)
2nd page: content related to the client with some bookmarks which fits
exactly in one page. representative will enter these user fields and
those fields are captured in the document. even with bookmarks data, it

exactly fits in a page

My problem. after running the dot file, the content of page is shifted
down by one line (after header) which makes the content to run to the
next page. i dont know if iam doing something wrong. i want to fit in
exactly in one page.

Any help is highly appreciated. 


4.OWC VB.NET - What am I doing wrong??

Hello, I am having trouble getting my code here to write out an
appropriate GIF image for a chart using the OWC components.  I am
calling the page as <img src ="theChartingPage.aspx"> , but am not
receiving the data back.

My original example worked ok, but I have done something here to mess
it up.  I do have the values coming from the database, but for
simplicity sake I am going to create a static array so we can eliminate
that from the potentional problem list.  Any help you can give would be
greatly appreciated!!

We will also assume the variables are all dimmed above.  I get no
runtime errors here just nothing for the value :/

        labelArray(0) = "Total"
        labelArray(1) = "Vacant"

        dataArray(0) = "1"
        dataArray(1) = "3"

        'Create a new chartspace:
        ChartSpace1 = New OWC.ChartSpace

        'Create a new chart within ChartSpace1:
        occupancyChart = ChartSpace1.Charts.Add(0)

        'Add a new dataseries within occupancyChart:
        occupancyChart_Series1 = occupancyChart.SeriesCollection.Add(0)

        'Define occupancyChart_Series1 as pie chart
        occupancyChart_Series1.Type =

        'Name the dataseries (name appears in Legend):

OWC.ChartSpecialDataSourcesEnum.chDataLiteral, "Chart1_Series1")

        'Populate values from array:

OWC.ChartSpecialDataSourcesEnum.chDataLiteral, labelArray)

OWC.ChartSpecialDataSourcesEnum.chDataLiteral, dataArray)

        'Format the chart elements.
        With occupancyChart
            .HasLegend = True
            .Legend.Position =
            .HasTitle = True
            .Title.Caption = "Total Occupancy For All Unit Types"
            .Axes(0).HasTitle = True
            .Axes(0).Title.Caption = "Total Units"
            .Axes(1).HasTitle = True
            .Axes(1).Title.Caption = "Total Vacant Units"
        End With

        'Return the new chart in GIF format.
        Response.Buffer = True
        Response.ContentType = "image/gif"
        Response.BinaryWrite(ChartSpace1.GetPicture("gif", 500, 400))

5.Public Folders: What am I doing wrong?

Hi all,

I'm not new to Outlook but I am new to Public Folders. I've had our admin 
create a public folder and set me as owner.

Outlook's help clearly states "Public folders can contain any type of 
Outlook folder item such as messages, appointments, contacts, tasks, journal 
entries, notes, forms, files, and postings" but when I add any type of item 
to a folder it just looks like a posting. The only other type of object I 
seem to be able to add is a file.

I can't find anything else in Outlook's help to show how to actually add 
anything to a public folder.

What am I missing/doing wrong?


6. What am I doing wrong?

7. What am I doing wrong!??

8. Outlook Custom Form...what am I doing wrong?



Who is online

Users browsing this forum: No registered users and 76 guest