Hello everyone, and thank you in advance for any assistance you can
provide with this query.

I've been trying to put together a script which when run will create an
e-mail message and attach all the files residing in a specific folder.
However, currently I'm getting an error and was hoping for some insight
and suggestions.

The script looks like this ....

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set myfolder = fso.GetFolder("C:\emailfolder\")
Set myfiles = myfolder.files
myItem.Subject = "This is the Subject"
Set myRecipient = myItem.Recipients.Add("myemail@myemail.co.uk")
Set myAttachments = myItem.Attachments
For Each MyFile in MyFiles
myAttachments.Add files(MyFile.Name), olByValue
Next
myItem.Display

I get a scripting error on Line: 10, Char: 3, Error: Type mismatch:
'files' which I'm assuming is referring to the files(MyFile.Name)
section of the script.

I originally produced the script with just a single attachment and this
was fine but upon inserting the code to look to add all the files in
the 'emailfolder' location then the error appeared.

Any suggestions would be most appreciated.

Darren Hermes
darreninwarrington at hotmail dot co dot uk

Re: E-Mail Attachment Script Problem by Michael

Michael
Sun Sep 11 10:01:22 CDT 2005

inline...

darreninwarrington@hotmail.co.uk wrote:
> Hello everyone, and thank you in advance for any assistance you can
> provide with this query.
>
> I've been trying to put together a script which when run will create
> an e-mail message and attach all the files residing in a specific
> folder. However, currently I'm getting an error and was hoping for
> some insight and suggestions.
>
> The script looks like this ....
>

Const olByValue = 1

> Set myOlApp = CreateObject("Outlook.Application")
> Set myItem = myOlApp.CreateItem(olMailItem)
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set myfolder = fso.GetFolder("C:\emailfolder\")
> Set myfiles = myfolder.files
> myItem.Subject = "This is the Subject"
> Set myRecipient = myItem.Recipients.Add("myemail@myemail.co.uk")
> Set myAttachments = myItem.Attachments
> For Each MyFile in MyFiles
> myAttachments.Add files(MyFile.Name), olByValue

myAttachments.Add MyFile.Path, olByValue, , MyFile.Name

> Next
> myItem.Display
>
> I get a scripting error on Line: 10, Char: 3, Error: Type mismatch:
> 'files' which I'm assuming is referring to the files(MyFile.Name)
> section of the script.
>
> I originally produced the script with just a single attachment and
> this was fine but upon inserting the code to look to add all the
> files in the 'emailfolder' location then the error appeared.
>
> Any suggestions would be most appreciated.
>
> Darren Hermes
> darreninwarrington at hotmail dot co dot uk

--
Michael Harris
Microsoft MVP Scripting





Re: E-Mail Attachment Script Problem by darreninwarrington

darreninwarrington
Sun Sep 11 10:27:23 CDT 2005

Excellent, many thanks.


Re: E-Mail Attachment Script Problem by Fan

Fan
Mon Sep 12 16:55:08 CDT 2005

Michael,

Is there anyway to by pass the Outlook security prompts such as 'A program
is trying to access to e-mail address you have stored in Outlook' and 'A
program is trying to automatically send e-mail on your behalf' when using
the script posted to send email?

Fan

"Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
news:%23l8e0HutFHA.3500@TK2MSFTNGP09.phx.gbl...
> inline...
>
> darreninwarrington@hotmail.co.uk wrote:
>> Hello everyone, and thank you in advance for any assistance you can
>> provide with this query.
>>
>> I've been trying to put together a script which when run will create
>> an e-mail message and attach all the files residing in a specific
>> folder. However, currently I'm getting an error and was hoping for
>> some insight and suggestions.
>>
>> The script looks like this ....
>>
>
> Const olByValue = 1
>
>> Set myOlApp = CreateObject("Outlook.Application")
>> Set myItem = myOlApp.CreateItem(olMailItem)
>> Set fso = CreateObject("Scripting.FileSystemObject")
>> Set myfolder = fso.GetFolder("C:\emailfolder\")
>> Set myfiles = myfolder.files
>> myItem.Subject = "This is the Subject"
>> Set myRecipient = myItem.Recipients.Add("myemail@myemail.co.uk")
>> Set myAttachments = myItem.Attachments
>> For Each MyFile in MyFiles
>> myAttachments.Add files(MyFile.Name), olByValue
>
> myAttachments.Add MyFile.Path, olByValue, , MyFile.Name
>
>> Next
>> myItem.Display
>>
>> I get a scripting error on Line: 10, Char: 3, Error: Type mismatch:
>> 'files' which I'm assuming is referring to the files(MyFile.Name)
>> section of the script.
>>
>> I originally produced the script with just a single attachment and
>> this was fine but upon inserting the code to look to add all the
>> files in the 'emailfolder' location then the error appeared.
>>
>> Any suggestions would be most appreciated.
>>
>> Darren Hermes
>> darreninwarrington at hotmail dot co dot uk
>
> --
> Michael Harris
> Microsoft MVP Scripting
>
>
>
>



Re: E-Mail Attachment Script Problem by Michael

Michael
Tue Sep 13 21:06:54 CDT 2005

Fan Fan wrote:
> Michael,
>
> Is there anyway to by pass the Outlook security prompts such as 'A
> program is trying to access to e-mail address you have stored in
> Outlook' and 'A program is trying to automatically send e-mail on
> your behalf' when using the script posted to send email?

outlook security prompts group:*.outlook - Google Groups
http://groups.google.com/groups?q=outlook%20security%20prompts%20group:*.outlook

--
Michael Harris
Microsoft MVP Scripting