:: LEAST I COULD DO FORUM ::: VB help needed... - :: LEAST I COULD DO FORUM ::

Jump to content

Page 1 of 1

VB help needed... ...because my brain's just not working well today

#1 User is offline   treehugger Icon

  • Group: Members
  • Posts: 258
  • Joined: 08-February 06
  • Gender:Female
  • Location:Ottawa, ON

Posted 09 July 2008 - 09:58 AM

I'm about to smack my computer ranting.gif

I have a program that dumps hundreds of draft emails into my Outlook's draft folder. In order to send them from there, I wrote a quick VB macro so that I didn't have to open each one and hit "send". My problem with the macro is that, every time you run it, it only sends exactly half the emails. I'm sure I've done something very obviously wrong but it's so obvious that, after staring at it for an hour, I can't see it. Can anyone help, please??
-------------
Code:
-------------
Sub Send_drafts()

Dim oNS As Outlook.NameSpace
Dim oFld As Outlook.MAPIFolder
Dim oItems As Outlook.Items
Dim oItem As Object

Set oNS = Application.GetNamespace("MAPI")

Set oFld = oNS.GetDefaultFolder(olFolderDrafts)

For Each oItem In oFld.Items

If oItem.To <> "" Then
oItem.Send
End If

Next

End Sub
0

#2 User is offline   Shluey Icon

  • Group: Members
  • Posts: 800
  • Joined: 21-December 07

Posted 09 July 2008 - 12:44 PM

Does it send the first half, last half, or every other?

You may want to give it a whirl without the foreach loop, I dont know VB syntax but replace it with something like:

For Index = oFld.Items.length, Index > 0, Index--
// Include some debugging information here, like oFld.items.Name > stdout
oFld.Items[index].send
next

That's obviously not changing anything that you're already doing except cycling backwards through the array, if that send method is actively changing something and removing that object from the array [or may likely some kind of linked list or whatever] it may be an indexing issue. Going from the end to the start could fix that. (Also I seem to recall VB starting it's array index at 1 and not 0, if that's not correct you'll need to start at length-1 and go to >=0.)

This post has been edited by Shluey: 09 July 2008 - 12:47 PM

0

#3 User is offline   treehugger Icon

  • Group: Members
  • Posts: 258
  • Joined: 08-February 06
  • Gender:Female
  • Location:Ottawa, ON

Posted 09 July 2008 - 12:51 PM

It's sending every second one.

I'll have a go at getting rid of the "each" after my boring update meeting this aft. Thanks for the suggestion smile.gif
0

#4 User is offline   Shluey Icon

  • Group: Members
  • Posts: 800
  • Joined: 21-December 07

Posted 09 July 2008 - 12:54 PM

I would say it is almost definitely an indexing issue then, imagine you have 4 e-mails in a linked list and the loop starts at 1.

E1 <--
E2
E3
E4

Now your send removes it, but the loop moves on the second object:

E2
E3 <--
E4

E-mail 2 gets skipped. Write a loop that starts at the end of the list and moves back to the beginning.
0

#5 User is online   Cybercat Icon

  • President of the Cyndi fanclub.
  • Group: Members
  • Posts: 6,978
  • Joined: 17-March 04
  • Location:Enschede, NL

Posted 09 July 2008 - 01:02 PM

Why would anyone want to send hundreds of e-mails at once anyway?
QUOTE
After all, you can't spell slaughter without laughter.

Surprise!
0

#6 User is offline   treehugger Icon

  • Group: Members
  • Posts: 258
  • Joined: 08-February 06
  • Gender:Female
  • Location:Ottawa, ON

Posted 09 July 2008 - 01:06 PM

Because we have thousands of companies that have to report to us every year and every year, several hundred of them make misatakes in their data and we need to contact them to get them to fix it. I have a nifty program that writes the individualized emails but I'm having a such a hard time getting the send program working properly.

Edit - It was doing exactly what you said Shluey. I have added an Items.Count and I'm trying to write a loop that counts down. It's getting there, slowly. (This is why they shouldn't have the environmental engineer writing code tongue.gif )

This post has been edited by treehugger: 09 July 2008 - 01:12 PM

0

#7 User is online   Cybercat Icon

  • President of the Cyndi fanclub.
  • Group: Members
  • Posts: 6,978
  • Joined: 17-March 04
  • Location:Enschede, NL

Posted 09 July 2008 - 01:16 PM

Ah. These days that may not be very wise though. Apparently it doesn't take much these days for some ISPs to consider you a spammer and start blocking your e-mails, not just for their own users but even when it comes to passing them on to the next in line. I play in a play by e-mail game and they have been on several ISPs blacklists now because they send out a whole bunch of e-mails at once (the turn files of that day.) It can be a real pain to get off such a list again too. If there's no huge time restraint you may be better off spreading them out over the day more.
QUOTE
After all, you can't spell slaughter without laughter.

Surprise!
0

#8 User is offline   treehugger Icon

  • Group: Members
  • Posts: 258
  • Joined: 08-February 06
  • Gender:Female
  • Location:Ottawa, ON

Posted 09 July 2008 - 02:38 PM

At certain times of the year, we send mailouts to all ~10,000 companies at once and so far we haven't had any issues with being blacklisted or blocked by spam filters. It's good advice though to spread out the sending just in case (and it means I could justify spending 2 whole days just sending emails).
0

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users