A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Redemption, Help with selecting E-mail Account



 
 
Thread Tools Search this Thread Display Modes
  #21  
Old January 30th 08, 08:12 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Redemption, Help with selecting E-mail Account

And where is olApp declared and instantiated? You have:

Set oNS = olApp.GetNamespace("MAPI")

but I don't see where olApp is created and instantiated. It looks like
you're actually using OutApp and instantiating it in the Mail_New_Version()
procedure, but after you try to use oNS, so at that point both OutApp and
olApp are Nothing.

Move your code that sets OutApp and oNS to before you try to use the
objects.

Comment out the On Error Resume Next line. Then step your code and make sure
you are getting a valid Outlook.Application object after the line Set OutApp
= CreateObject("Outlook.Application"). Make sure that oNS is valid after
executing the line Set oNS = OutApp.GetNamespace("MAPI").

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sean" wrote in message
...
Ken, best thing I can do is post the full code as it is again

Sub Mail_New_Version()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim oNS As Outlook.NameSpace
Dim NameSpace As Object
Dim RDOSession As Object
Set oNS = olApp.GetNamespace("MAPI")



With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheets to a new workbook
Sourcewb.Sheets(Array("Mail", "YTD")).Copy
Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
'We exit the sub when your answer is NO in the security
dialog that you only
'see when you copy a sheet from a xlsm file with macro's
disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With


'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-
mmm-yy h-mm")



ActiveWindow.TabRatio = 0.908


Set OutApp = CreateObject("Outlook.Application")
Set oNS = OutApp.GetNamespace("MAPI")
oNS.Logon
Set OutMail = OutApp.CreateItem(0)

For Each cell In ThisWorkbook.Sheets("Mail") _
.Columns("BA").Cells.SpecialCells(xlCellTypeConsta nts)
If cell.Value Like "?*@?*.?*" Then
strto = strto & cell.Value & ";"
End If
Next
strto = Left(strto, Len(strto) - 1)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum

On Error Resume Next



Set Session = CreateObject("Redemption.RDOSession")



MsgBox TypeName(oNS)

Session.MAPIOBJECT = oNS.MAPIOBJECT

Set Account = Session.Accounts("ABC Reporting")
.Account = Account

With OutMail
.To = ""
.CC = ""
.BCC = strto
.Subject = ThisWorkbook.Sheets("Mail").Range("A1").Value
.Body = ""
.Attachments.Add Destwb.FullName
.ReadReceiptRequested = True
.Importance = 1
.Save
Dim sID As String
sID = .EntryID
End With
Set Msg = Session.GetItemFromID(sID)
Msg.Account = Account
.Subject = .Subject
.Save
.Send
End With
On Error GoTo 0
.Close savechanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub


Ads
  #22  
Old February 2nd 08, 12:19 PM posted to microsoft.public.outlook.program_vba
Sean
external usenet poster
 
Posts: 20
Default Redemption, Help with selecting E-mail Account

Ken, thanks for your reply, however I'm unsure of exactly what you
mean. I'm not an IT person and my original excel vb was taken from a
standard e-mail post (which worked), so I'm not clear how to
incorporate the redemption element to achieve what I am looking for

  #23  
Old February 2nd 08, 07:31 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Redemption, Help with selecting E-mail Account

Please post some of the preceeding thread when you reply, it makes it much
harder to follow the thread otherwise.

At some point, IT person or not, you're going to need to be able to step
your code and debug things to get things working the way you want. I'd
recommend buying a good beginner VBA book so you know how to do the basics.

You really should have something in the To field, a lot of email programs
will consider an email with only Bcc as a spam. Also, usually it's best to
set a Recipient object as olBCC instead of the way it's being done here.

I haven't tested this code. I cleaned up undeclared Outlook and Redemption
objects, released them all, and merged the Outlook and Redemption code
together. Anything else is your responsibility.

Sub Mail_New_Version()
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim sh As Worksheet
Dim oNS As Outlook.NameSpace
Dim oSession As Redemption.RDOSession
Dim oAccount As Redemption.RDOAccount
Dim sID As String
Dim Msg As Redemption.RDOMail

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set Sourcewb = ActiveWorkbook

'Copy the sheets to a new workbook
Sourcewb.Sheets(Array("Mail", "YTD")).Copy
Set Destwb = ActiveWorkbook

'Determine the Excel version and file extension/format
With Destwb
If Val(Application.Version) 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
'We exit the sub when your answer is NO in the security
dialog that you only
'see when you copy a sheet from a xlsm file with macro's
disabled.
If Sourcewb.Name = .Name Then
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Your answer is NO in the security dialog"
Exit Sub
Else
Select Case Sourcewb.FileFormat
Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
Case 52:
If .HasVBProject Then
FileExtStr = ".xlsm": FileFormatNum = 52
Else
FileExtStr = ".xlsx": FileFormatNum = 51
End If
Case 56: FileExtStr = ".xls": FileFormatNum = 56
Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If
End If
End With


'Save the new workbook/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-
mmm-yy h-mm")



ActiveWindow.TabRatio = 0.908


For Each cell In ThisWorkbook.Sheets("Mail") _
.Columns("BA").Cells.SpecialCells(xlCellTypeConsta nts)
If cell.Value Like "?*@?*.?*" Then
strto = strto & cell.Value & ";"
End If
Next
strto = Left(strto, Len(strto) - 1)

With Destwb
.SaveAs TempFilePath & TempFileName & FileExtStr,
FileFormat:=FileFormatNum

On Error Resume Next

Set OutApp = CreateObject("Outlook.Application")
Set oNS = OutApp.GetNamespace("MAPI")
oNS.Logon
Set OutMail = OutApp.CreateItem(0)

Set oSession = CreateObject("Redemption.RDOSession")

MsgBox TypeName(oNS)

oSession.MAPIOBJECT = oNS.MAPIOBJECT

Set oAccount = oSession.Accounts("ABC Reporting")

With OutMail
.To = ""
.CC = ""
.BCC = strto
.Subject = ThisWorkbook.Sheets("Mail").Range("A1").Value
.Body = ""
.Attachments.Add Destwb.FullName
.ReadReceiptRequested = True
.Importance = 1

.Save
sID = .EntryID

Set Msg = oSession.GetMessageFromID(sID)
Msg.Account = oAccount

.Subject = .Subject
.Save

.Send
End With

On Error GoTo 0
.Close savechanges:=False
End With

'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr

Set Sourcewb = Nothing
Set Destwb = Nothing
Set sh = Nothing

Set oAccount = Nothing
Set Msg = Nothing

oSession.Logoff
Set oSession = Nothing

Set OutMail = Nothing
Set oNS = Nothing

OutApp.Quit
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Sean" wrote in message
...
Ken, thanks for your reply, however I'm unsure of exactly what you
mean. I'm not an IT person and my original excel vb was taken from a
standard e-mail post (which worked), so I'm not clear how to
incorporate the redemption element to achieve what I am looking for


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook XP - selecting default account when sending attachements via "sent to:" Immanentny Outlook - General Queries 0 February 20th 07 07:45 AM
Automatically selecting email account Ski Outlook - General Queries 1 August 14th 06 01:36 PM
Selecting Addresses for a new mail message flwmims Outlook - General Queries 2 August 7th 06 04:53 PM
Selecting account to send from treehstn Outlook - Installation 1 March 4th 06 06:28 PM
Selecting outlook account via code John Outlook - General Queries 2 January 16th 06 02:17 PM


All times are GMT +1. The time now is 09:39 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.