I'm using the following script to send an email with a .pdf attachment.

Option Explicit:
Dim ol:
Dim myItem:
Dim Args:
Dim FMData1:
Dim FMData2:
Const olMailItem = 0:
Set Args = WScript.Arguments:
FMData1 = Args(0):
FMData2 = Args(1):
Set ol = CreateObject ("outlook.application"):
Set myItem = ol.CreateItem(olMailItem):
With myItem:.To = FMData2:
.Subject = "Some subject":
.Body = "Some information":
.Attachments.add "U:\My Documents\Attachment.pdf":
.Send:
End With:
Set ol = Nothing:
Set myItem = Nothing:
Set FMData1 = Nothing:
Set FMData2 = Nothing:


The .pdf attachment is created using Acrobat Distiller just before this
script is called. Normally everything works just fine, but every once in a
while, I get an error message indicating Outlook could not find the attached
file for ".Attachments.add" I'm assuming the reason is Distiller had not yet
released the file.

I'd like to trap the error message and create a loop which would pause 1
sec, then issue another ".Attachment.add" command exiting the loop when no
error was returned or after 10 tries.

Any help with this will be appreciated.

Re: Error Handling by name

name
Wed Feb 11 01:52:43 CST 2004

There must be hundreds if not thousands who would like ADOBE to
overtake HTML into a binary component for Internet data exchange.

Get flash and wish yourself good luck.


===========

Not on my machine though.



"Barry Brown" <barrysb@widomaker.com> wrote in message
news:BC4F0895.23546%barrysb@widomaker.com...
> I'm using the following script to send an email with a .pdf attachment.
>
> Option Explicit:
> Dim ol:
> Dim myItem:
> Dim Args:
> Dim FMData1:
> Dim FMData2:
> Const olMailItem = 0:
> Set Args = WScript.Arguments:
> FMData1 = Args(0):
> FMData2 = Args(1):
> Set ol = CreateObject ("outlook.application"):
> Set myItem = ol.CreateItem(olMailItem):
> With myItem:.To = FMData2:
> .Subject = "Some subject":
> .Body = "Some information":
> .Attachments.add "U:\My Documents\Attachment.pdf":
> .Send:
> End With:
> Set ol = Nothing:
> Set myItem = Nothing:
> Set FMData1 = Nothing:
> Set FMData2 = Nothing:
>
>
> The .pdf attachment is created using Acrobat Distiller just before this
> script is called. Normally everything works just fine, but every once in a
> while, I get an error message indicating Outlook could not find the
attached
> file for ".Attachments.add" I'm assuming the reason is Distiller had not
yet
> released the file.
>
> I'd like to trap the error message and create a loop which would pause 1
> sec, then issue another ".Attachment.add" command exiting the loop when no
> error was returned or after 10 tries.
>
> Any help with this will be appreciated.
>
>
>


Re: Error Handling by Barry

Barry
Wed Feb 11 06:38:23 CST 2004

Sorry, this reply has nothing to do with my question. I need to add an error
handling sequence to my Outlook script. I'm not sure if it can be inserted
within a With/End With routine.

in article #1#DJQH8DHA.3360@tk2msftngp13.phx.gbl, name at nospam@user.com
wrote on 2/11/04 2:52 AM:

> There must be hundreds if not thousands who would like ADOBE to
> overtake HTML into a binary component for Internet data exchange.
>
> Get flash and wish yourself good luck.
>
>
> ===========
>
> Not on my machine though.
>
>
>
> "Barry Brown" <barrysb@widomaker.com> wrote in message
> news:BC4F0895.23546%barrysb@widomaker.com...
>> I'm using the following script to send an email with a .pdf attachment.
>>
>> Option Explicit:
>> Dim ol:
>> Dim myItem:
>> Dim Args:
>> Dim FMData1:
>> Dim FMData2:
>> Const olMailItem = 0:
>> Set Args = WScript.Arguments:
>> FMData1 = Args(0):
>> FMData2 = Args(1):
>> Set ol = CreateObject ("outlook.application"):
>> Set myItem = ol.CreateItem(olMailItem):
>> With myItem:.To = FMData2:
>> .Subject = "Some subject":
>> .Body = "Some information":
>> .Attachments.add "U:\My Documents\Attachment.pdf":
>> .Send:
>> End With:
>> Set ol = Nothing:
>> Set myItem = Nothing:
>> Set FMData1 = Nothing:
>> Set FMData2 = Nothing:
>>
>>
>> The .pdf attachment is created using Acrobat Distiller just before this
>> script is called. Normally everything works just fine, but every once in a
>> while, I get an error message indicating Outlook could not find the
> attached
>> file for ".Attachments.add" I'm assuming the reason is Distiller had not
> yet
>> released the file.
>>
>> I'd like to trap the error message and create a loop which would pause 1
>> sec, then issue another ".Attachment.add" command exiting the loop when no
>> error was returned or after 10 tries.
>>
>> Any help with this will be appreciated.
>>
>>
>>
>


Re: Error Handling by Fosco

Fosco
Wed Feb 11 22:59:32 CST 2004

"Barry Brown"

> I get an error message indicating Outlook could not find the
> attached file for ".Attachments.add"
> I'm assuming the reason is Distiller had not yetreleased the file.


Set Fso = CreateObject("Scripting.FileSystemObject")
Do Until Fso.FileExists("U:\My Documents\Attachment.pdf")
wscript.sleep 10
Loop
Msgbox "File created"

--
Fosco








Re: Error Handling by Barry

Barry
Thu Feb 12 08:22:44 CST 2004

Thanks for your response. I should have mentioned this in my original post,
but using a different system,I've already tried a fileExists test, which did
not solve the error problem. I'm not sure if a function indicates whether
the file is in use or not. This appears to be causing the error - Distiller
is still using the file when Outlook attempts to attach it to the email
message. Therefore, I need to trap the error and pause then retry.


in article UKDWb.299126$_P.10267921@news4.tin.it, Fosco at fake@fake.invalid
wrote on 2/11/04 11:59 PM:

> "Barry Brown"
>
>> I get an error message indicating Outlook could not find the
>> attached file for ".Attachments.add"
>> I'm assuming the reason is Distiller had not yetreleased the file.
>
>
> Set Fso = CreateObject("Scripting.FileSystemObject")
> Do Until Fso.FileExists("U:\My Documents\Attachment.pdf")
> wscript.sleep 10
> Loop
> Msgbox "File created"
>
> --
> Fosco
>
>
>
>
>
>
>


Re: Error Handling by Jeromy

Jeromy
Thu Feb 12 16:23:45 CST 2004

you could try something like the following:
on error resume next
.Attachments.add "U:\My Documents\Attachment.pdf":
if err then
do while err.number <> 0 or iRetryCount >= 10
err.clear()
iRetryCount = iRetryCount + 1
wscript.sleep(1000)
.Attachments.add "U:\My Documents\Attachment.pdf"
loop
end if
on error goto 0

tx

--
Jeromy Statia [MSFT]

This posting is provided "AS IS" with no warranties, and confers no rights.


"Barry Brown" <barrysb@widomaker.com> wrote in message
news:BC4F0895.23546%barrysb@widomaker.com...
> I'm using the following script to send an email with a .pdf attachment.
>
> Option Explicit:
> Dim ol:
> Dim myItem:
> Dim Args:
> Dim FMData1:
> Dim FMData2:
> Const olMailItem = 0:
> Set Args = WScript.Arguments:
> FMData1 = Args(0):
> FMData2 = Args(1):
> Set ol = CreateObject ("outlook.application"):
> Set myItem = ol.CreateItem(olMailItem):
> With myItem:.To = FMData2:
> .Subject = "Some subject":
> .Body = "Some information":
on error resume next
> .Attachments.add "U:\My Documents\Attachment.pdf":
if err then
do while err.number <> 0 or iRetryCount >= 5
wscript.sleep(1000)
.Attachments.add "U:\My Documents\Attachment.pdf"
loop
end if
> .Send:
> End With:
> Set ol = Nothing:
> Set myItem = Nothing:
> Set FMData1 = Nothing:
> Set FMData2 = Nothing:
>
>
> The .pdf attachment is created using Acrobat Distiller just before this
> script is called. Normally everything works just fine, but every once in a
> while, I get an error message indicating Outlook could not find the
attached
> file for ".Attachments.add" I'm assuming the reason is Distiller had not
yet
> released the file.
>
> I'd like to trap the error message and create a loop which would pause 1
> sec, then issue another ".Attachment.add" command exiting the loop when no
> error was returned or after 10 tries.
>
> Any help with this will be appreciated.
>
>
>



Re: Error Handling by Fosco

Fosco
Fri Feb 13 09:22:24 CST 2004

"Barry Brown"
> I'm not sure if a function indicates whether the file is in use or not.
> This appears to be causing the error - Distiller is still using the file

copied from here :
http://groups.google.com/advanced_group_search
www.google.com

http://www.allmyfaqs.com/faq.pl?How_to_post

Alexander Mueller wrote:

> in order to share resources in 'mutually exclusive'
> manner Windows uses Mutex-kernelobjects among others. For
> Windows 98 there was a tiny ActiveX-Dll "AMutex.Mutex"
> http://pragmaticlee.safedataisp.net/ -> testmutex.zip
> which enables use of muteces for WSH on this Platform.
> It doesnt' seem to work for me on XP.
> Does anyone know another mutex/semaphore
> wrapper for XP?

Hi

I use a file lock technique for this, that way you don't need to use any 3rd
party component at all. If the script that has locked the file (created the
mutex) crashes, the lock will automatically be removed (mutex will be
released).

Const ForAppending = 8
' file that will be locked
sLckFile = "k:\script.lck"
Set oFSO = CreateObject("Scripting.FileSystemObject")
bUpdFinished = False
iLoops = 0
On Error Resume Next
Do
' open for appending
Set f = oFSO.OpenTextFile(sLckFile, ForAppending, True)
If Err.Number = 70 Then
'Permission denied error
' Waiting 1/2 a second before trying again
WScript.Sleep 500
ElseIf Err.Number <> 0 then
WScript.Echo "Unexpected Error #: " & Err.Number
bUpdFinished = True
Else
On Error GoTo 0
' do the job here, the file will now be locked by this script and
' nobody else will be able to continue until the f.Close instruction
'below is run...
' close the file so others can be able to continue
f.Close
bUpdFinished = True
End If
Err.Clear
Loop Until bUpdFinished
On Error GoTo 0
--
torgeir

'| Is there a way, with WSH and perhaps ADSI, to look at a particular file
'and
'| see if it is currently open? Ideally I would like to know who has it open,
'| but just knowing it is really open would get me what I really need.

'Assuming that you know that you have no permission issues with the file, an
'old scripting workaround (I think I got it from one of Torgeir Bakken's
'posts) is to open the file for append, error-trapped, and test for error 70
'(permission denied). It's only kicked up for permission and in-use issues.
'Coarse, but works fine for local computer usage. (air code)

'---
set oFso= createobject("scripting.fileSystemObject")
on error resume next
sfile="C:\TEST.txt"
set oFile= oFso.openTextFile(sfile, 8, false)
nErr= err: sErr= err.description: err.clear
oFile.close
on error goto 0
select case nErr
case 0: msgbox "File is not in use."
case 70: msgbox "File is in use."
case else: msgbox "Error: " & nErr & vbCr _
& sErr
end select

'---
'Joe Earnest

Or run distiller and wait for close

object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])

bWaitOnReturn
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the
next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code
returned by the program. If set to false (the default), the Run method returns immediately after starting the program,
automatically returning 0 (not to be interpreted as an error code).

set oShell = CreateObject("WScript.Shell")
oShell.run"calc",1,true
' run Acrobat Distiller
msgbox "closed"
'wait close
'run your outlook stuff

or

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("notepad")
Do While oExec.Status = 0
WScript.Sleep 10
Loop
WScript.Echo "status" &" >>>"& oExec.Status &" " &"Closed"

--
Fosco