Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default Run time error

When I run this code I am getting the error Run-Time error
on this part of the code... "objAttachmt.Source =
ComboBox1.Value"

Below is the entire code.

Please help.

Thanx

Private Sub CommandButton4_Click()
If CheckBox2.Value = True And ComboBox1.Value = "Please
Select Agent to Email" Then
MsgBox "Input Error!" & vbCrLf & "You Must Select
an Agent", vbCritical, "Input Error"
Exit Sub
Else
Dim objSession As Object, objMessage As Object,
objOneRecip As Object
Dim objAttachmt As Object

Set objSession = CreateObject("MAPI.Session")
objSession.Logon
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Stats"
objMessage.Text = ""
Set objAttachmt = objMessage.Attachments.Add
objAttachmt.Source = ComboBox1.Value
'objAttachmt.Source = ("C:\Sheets.xls")
'Set objOneRecip = objMessage.Recipients.Add
'objOneRecip.Name = "
'objOneRecip.Type = 1
'objOneRecip.Resolve
objMessage.Send showDialog:=True
objSession.Logoff
End If
MsgBox "done"
Exit Sub

If CheckBox1.Value = True Then
MsgBox "insert code2 here"
Else
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Run time error

I've not tried to reproduce the problem.

Could you try a couple of things:
Does the line: 'objAttachmt.Source = ("C:\Sheets.xls") work?
Set a breakpoint on the line which errors. Then when it activates, type the
following into the immediate window (activate it via View menu | Immediate
Window):
?ComboBox1.Value

Tell me what that returns.

Cheers



"Todd Huttenstine" wrote in message
...
When I run this code I am getting the error Run-Time error
on this part of the code... "objAttachmt.Source =
ComboBox1.Value"

Below is the entire code.

Please help.

Thanx

Private Sub CommandButton4_Click()
If CheckBox2.Value = True And ComboBox1.Value = "Please
Select Agent to Email" Then
MsgBox "Input Error!" & vbCrLf & "You Must Select
an Agent", vbCritical, "Input Error"
Exit Sub
Else
Dim objSession As Object, objMessage As Object,
objOneRecip As Object
Dim objAttachmt As Object

Set objSession = CreateObject("MAPI.Session")
objSession.Logon
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Stats"
objMessage.Text = ""
Set objAttachmt = objMessage.Attachments.Add
objAttachmt.Source = ComboBox1.Value
'objAttachmt.Source = ("C:\Sheets.xls")
'Set objOneRecip = objMessage.Recipients.Add
'objOneRecip.Name = "
'objOneRecip.Type = 1
'objOneRecip.Resolve
objMessage.Send showDialog:=True
objSession.Logoff
End If
MsgBox "done"
Exit Sub

If CheckBox1.Value = True Then
MsgBox "insert code2 here"
Else
End If
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default Run time error

Hey I used the following code... It is working now. I
had to create a new variable.

Dim sStr As String
Dim objAttachmt As Object
sStr = ComboBox1.Value
Worksheets(sStr).Copy
ActiveWorkbook.SaveAs "C:\Stats.xls", _
FileFormat:=xlWorkbookNormal
ActiveWorkbook.Close SaveChanges:=False
Dim objSession As Object, objMessage As Object,
objOneRecip As Object
Set objSession = CreateObject("MAPI.Session")
objSession.Logon
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Stats"
objMessage.Text = ""
'Set objOneRecip = objMessage.Recipients.Add
'objOneRecip.Name = "
'objOneRecip.Type = 1
'objOneRecip.Resolve
'objMessage.Attachments.Add "C:\Stats.xls"
Set objAttachmt = objMessage.Attachments.Add
objAttachmt.Source = ("C:\Stats.xls")
objMessage.Send showDialog:=True
objSession.Logoff
On Error Resume Next
Kill "C:\Stats.xls"



-----Original Message-----
I've not tried to reproduce the problem.

Could you try a couple of things:
Does the line: 'objAttachmt.Source = ("C:\Sheets.xls")

work?
Set a breakpoint on the line which errors. Then when it

activates, type the
following into the immediate window (activate it via View

menu | Immediate
Window):
?ComboBox1.Value

Tell me what that returns.

Cheers



"Todd Huttenstine"

wrote in message
...
When I run this code I am getting the error Run-Time

error
on this part of the code... "objAttachmt.Source =
ComboBox1.Value"

Below is the entire code.

Please help.

Thanx

Private Sub CommandButton4_Click()
If CheckBox2.Value = True And ComboBox1.Value = "Please
Select Agent to Email" Then
MsgBox "Input Error!" & vbCrLf & "You Must

Select
an Agent", vbCritical, "Input Error"
Exit Sub
Else
Dim objSession As Object, objMessage As Object,
objOneRecip As Object
Dim objAttachmt As Object

Set objSession = CreateObject("MAPI.Session")
objSession.Logon
Set objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = "Stats"
objMessage.Text = ""
Set objAttachmt = objMessage.Attachments.Add
objAttachmt.Source = ComboBox1.Value
'objAttachmt.Source = ("C:\Sheets.xls")
'Set objOneRecip = objMessage.Recipients.Add
'objOneRecip.Name

= "
'objOneRecip.Type = 1
'objOneRecip.Resolve
objMessage.Send showDialog:=True
objSession.Logoff
End If
MsgBox "done"
Exit Sub

If CheckBox1.Value = True Then
MsgBox "insert code2 here"
Else
End If
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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Receiving run-time error only part of the time [email protected] Excel Discussion (Misc queries) 0 August 11th 07 12:01 AM
run-time error '91'-Close Button error ASCO IS Help Excel Discussion (Misc queries) 1 May 8th 06 04:25 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM


All times are GMT +1. The time now is 05:56 PM.

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

About Us

"It's about Microsoft Excel"