Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default CreateObject("Outlook.Application")

Hi,

I have procedure for sending mail. The problem is that the procedure will
work the first time it is executed but not the second time then the third
time it will work but not the fourth time and so on.

The sendEmail procedure is below.

Any help will be very much appreciated!

Public Sub sendMail()
On Error Resume Next

Dim oLApp As Object
Dim eMail As Object
Dim thisWb As String


thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name
Set oLApp = CreateObject("Outlook.Application")
Set eMail = oLApp.CreateItem(olMailItem)

With eMail
.To = "
.Subject = "some subject"
.Attachments.Add (thisWb)
.Display
End With

Set eMail = Nothing
Set oLApp = Nothing
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default CreateObject("Outlook.Application")

Try this

Set olApp = Nothing
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
On Error GoTo 0
If olApp Is Nothing Then
Set olApp = CreateObject("Outlook.Application")
End If


I'm betting that the first time you run it, Outlook is not open and the
second time it is.
--
HTH,

Barb Reinhardt



"Howard31" wrote:

Hi,

I have procedure for sending mail. The problem is that the procedure will
work the first time it is executed but not the second time then the third
time it will work but not the fourth time and so on.

The sendEmail procedure is below.

Any help will be very much appreciated!

Public Sub sendMail()
On Error Resume Next

Dim oLApp As Object
Dim eMail As Object
Dim thisWb As String


thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name
Set oLApp = CreateObject("Outlook.Application")
Set eMail = oLApp.CreateItem(olMailItem)

With eMail
.To = "
.Subject = "some subject"
.Attachments.Add (thisWb)
.Display
End With

Set eMail = Nothing
Set oLApp = Nothing
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default CreateObject("Outlook.Application")

FWIW, you can replace



thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name

with

thisWS = Thisworkbook.fullname

--
HTH,

Barb Reinhardt



"Howard31" wrote:

Hi,

I have procedure for sending mail. The problem is that the procedure will
work the first time it is executed but not the second time then the third
time it will work but not the fourth time and so on.

The sendEmail procedure is below.

Any help will be very much appreciated!

Public Sub sendMail()
On Error Resume Next

Dim oLApp As Object
Dim eMail As Object
Dim thisWb As String


thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name
Set oLApp = CreateObject("Outlook.Application")
Set eMail = oLApp.CreateItem(olMailItem)

With eMail
.To = "
.Subject = "some subject"
.Attachments.Add (thisWb)
.Display
End With

Set eMail = Nothing
Set oLApp = Nothing
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default CreateObject("Outlook.Application")

Thanks Barb Reinhardt! I'll try it out. By the way is "Thisworkbook.fullname"
availble in xl2003?

"Barb Reinhardt" wrote:

FWIW, you can replace



thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name

with

thisWS = Thisworkbook.fullname

--
HTH,

Barb Reinhardt



"Howard31" wrote:

Hi,

I have procedure for sending mail. The problem is that the procedure will
work the first time it is executed but not the second time then the third
time it will work but not the fourth time and so on.

The sendEmail procedure is below.

Any help will be very much appreciated!

Public Sub sendMail()
On Error Resume Next

Dim oLApp As Object
Dim eMail As Object
Dim thisWb As String


thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name
Set oLApp = CreateObject("Outlook.Application")
Set eMail = oLApp.CreateItem(olMailItem)

With eMail
.To = "
.Subject = "some subject"
.Attachments.Add (thisWb)
.Display
End With

Set eMail = Nothing
Set oLApp = Nothing
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default CreateObject("Outlook.Application")

FullName is available in xl2003.


"Howard31" wrote in message
...
Thanks Barb Reinhardt! I'll try it out. By the way is
"Thisworkbook.fullname"
availble in xl2003?

"Barb Reinhardt" wrote:

FWIW, you can replace



thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name

with

thisWS = Thisworkbook.fullname

--
HTH,

Barb Reinhardt



"Howard31" wrote:

Hi,

I have procedure for sending mail. The problem is that the procedure
will
work the first time it is executed but not the second time then the
third
time it will work but not the fourth time and so on.

The sendEmail procedure is below.

Any help will be very much appreciated!

Public Sub sendMail()
On Error Resume Next

Dim oLApp As Object
Dim eMail As Object
Dim thisWb As String


thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name
Set oLApp = CreateObject("Outlook.Application")
Set eMail = oLApp.CreateItem(olMailItem)

With eMail
.To = "
.Subject = "some subject"
.Attachments.Add (thisWb)
.Display
End With

Set eMail = Nothing
Set oLApp = Nothing
End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default CreateObject("Outlook.Application")

Thanks JLGWhiz!

"JLGWhiz" wrote:

FullName is available in xl2003.


"Howard31" wrote in message
...
Thanks Barb Reinhardt! I'll try it out. By the way is
"Thisworkbook.fullname"
availble in xl2003?

"Barb Reinhardt" wrote:

FWIW, you can replace



thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name

with

thisWS = Thisworkbook.fullname

--
HTH,

Barb Reinhardt



"Howard31" wrote:

Hi,

I have procedure for sending mail. The problem is that the procedure
will
work the first time it is executed but not the second time then the
third
time it will work but not the fourth time and so on.

The sendEmail procedure is below.

Any help will be very much appreciated!

Public Sub sendMail()
On Error Resume Next

Dim oLApp As Object
Dim eMail As Object
Dim thisWb As String


thisWb = ThisWorkbook.Path & "\" & ThisWorkbook.Name
Set oLApp = CreateObject("Outlook.Application")
Set eMail = oLApp.CreateItem(olMailItem)

With eMail
.To = "
.Subject = "some subject"
.Attachments.Add (thisWb)
.Display
End With

Set eMail = Nothing
Set oLApp = Nothing
End Sub



.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CreateObject("Excel.Application") Olivia Towery Excel Worksheet Functions 4 June 12th 06 12:07 AM
CreateObject("InternetExplorer.Application") shart[_9_] Excel Programming 1 January 2nd 06 05:14 PM
Set OutApp = CreateObject("Outlook.Application") - Runtime error 429 Buffyslay Excel Programming 2 July 20th 05 05:06 PM
ASP: CreateObject("Excel.Application") IIS 6.0 Win2003 Mau[_2_] Excel Programming 0 July 20th 05 11:45 AM
CreateObject("Excel.Application") - Access denied Luca[_2_] Excel Programming 0 February 6th 04 01:21 PM


All times are GMT +1. The time now is 01:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"