trying to email workbook from VB6, getting error 1004

M

Mike S

I'm using this code from VB6 to open a workbook then email it. The
workbook opens and I can read from it, write to it, format cells, etc,
but when I try to send mail I get an error:

'OutputFile contains a valid path to a working .xls file

Set oExcel = CreateObject("Excel.Application")
oExcel.UserControl = False 'do not let user interact with sheet
Sleep 1000
oExcel.Visible = DisplayExcel
Set oBook = oExcel.Workbooks.Open(OutputFile)
Sleep 1000
oBook.SendMail "(e-mail address removed)", "Excel Email Test"

Run-time error '1004'
Method 'SendMail' of object _Workbook' failed

I would like to be able to send the workbook from any version of Excel
2000 or later, on any OS XP or later, if possible.

Any suggestions would be appreciated.
Mike
 
G

GS

Mike S was thinking very hard :
I'm using this code from VB6 to open a workbook then email it. The workbook
opens and I can read from it, write to it, format cells, etc, but when I try
to send mail I get an error:

'OutputFile contains a valid path to a working .xls file

Set oExcel = CreateObject("Excel.Application")
oExcel.UserControl = False 'do not let user interact with sheet
Sleep 1000
oExcel.Visible = DisplayExcel
Set oBook = oExcel.Workbooks.Open(OutputFile)
Sleep 1000
oBook.SendMail "(e-mail address removed)", "Excel Email Test"

Run-time error '1004'
Method 'SendMail' of object _Workbook' failed

I would like to be able to send the workbook from any version of Excel 2000
or later, on any OS XP or later, if possible.

Any suggestions would be appreciated.
Mike

Hi Mike,
Is there any reason why you can't execute Excel's File>Send To>Mail
Recipient (as attachment) menuitem while the workbook is active?
 
M

mscir

GS said:
Mike S was thinking very hard :

Hi Mike,
Is there any reason why you can't execute Excel's File>Send To>Mail
Recipient (as attachment) menuitem while the workbook is active?

I'm automating Excel from Visual Basic 6. I decided to use a different
approach: simulating right clicking on the file in the Windows file
explorer then selecting Send To > Mail Recipient, that works great. I
think the problem above was caused because I don't have Outlook
configured, but the problem is solved. Thanks for replying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top