By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

CDO--Failure transmitting PDF as attachment via email from VB, VBA

P: n/a
I am using CDO to email a file as an attachment. The receiver receives
the file, but when he opens the file (tried using both Acrobat Reader
6 and 5), he gets "There was an error opening this document. The file
is damaged and could not be repaired." (similar error on Acrobat
Reader 5--Root object is missing) This pdf file opens fine on the
workstation from where I am transmitting. I have tried other pdf
files, but exact problem happens with all the pdf files. I tried
copying this suppossedly damaged file to other machine, assuming the
machine on which I am opening has Acrobat installed incorrectly, but
on other machines also, I get the same error. I also tried putting
sleep before sending, assuming that would solve the problem, but of no
avail. I tried transmitting other types of files, such as txt, mdb,
dbf, and exe. Those transmit fine and open correctly on the receiving
end. Just as a note that the size of the pdf file on the receiving end
changes (though slightly--increases). I know this is not good, but I
am not doing anything, which would change the size.

Could anybody help me solve this problem, so I can successfully
transmit pdf files, using CDO?

Thanks
---------------
Public Sub EmailPDF()
Dim iMsg, iConf, Flds, Fld
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
iMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")
= 2
iMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")
= "smarthost"
iMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")
= 25

With iMsg
Set .Configuration = iConf
.To = """User A"" <ab*@xyz.com>"
.From = """User B"" <de*@xyz.com>"
.Subject = "Attached Doc"
.AddAttachment "c:\abc.pdf"
.send
End With
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In your sample code you do not appear to be using Flds anywhere:

Set Flds = iConf.Fields

and iConf is just an object of type "CDO.Configuration"

With iMsg
Set .Configuration = iConf

I honestly don't know anything about CDO applications, but a lot of
times I find answers to things from questions. You appear to be setting
the configurations.Fields.Item of your message object, iMsg, here:

iMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/sendusing") = 2
iMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/smtpserver") = "smarthost"
iMsg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/smtpserverport") = 25

would that be your Flds object? I am not seeing the connection between
iMsg and iConf. Comparing this to Excel, it seems like you are setting
a Range object to Excel.Range but you are not assigning any parameters
to it like rng = Range("A1:D5"), just rng.

Set iMsg.Configuration = iConf

set rng = Excelobj

Hope these questions help you find your answer.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2

P: n/a
On 23 Jul 2004 07:35:45 -0700, gu*****@yahoo.com (gudia) wrote:
I am using CDO to email a file as an attachment. The receiver receives
the file, but when he opens the file (tried using both Acrobat Reader
6 and 5), he gets "There was an error opening this document. The file
is damaged and could not be repaired." (similar error on Acrobat
Reader 5--Root object is missing) This pdf file opens fine on the
workstation from where I am transmitting. I have tried other pdf
files, but exact problem happens with all the pdf files. I tried
copying this suppossedly damaged file to other machine, assuming the
machine on which I am opening has Acrobat installed incorrectly, but
on other machines also, I get the same error. I also tried putting
sleep before sending, assuming that would solve the problem, but of no
avail. I tried transmitting other types of files, such as txt, mdb,
dbf, and exe. Those transmit fine and open correctly on the receiving
end. Just as a note that the size of the pdf file on the receiving end
changes (though slightly--increases). I know this is not good, but I
am not doing anything, which would change the size.

Could anybody help me solve this problem, so I can successfully
transmit pdf files, using CDO?


Some thoughts...

Have you tried sending the file manually, without the programming? If
you can send it in Outlook or some other e-mail program, then if he
still gets the error, you've eliminated CDO as the cause.

If you can open the file fine on your side on several workstations,
it's remotely possible that something is happening to the MIME in an
intermediate gateway/e-mail server, OR (more likely) maybe something
is wrong with your friend's Acrobat Reader installation...

- snip -
_______________________
Michael B. Johnson
Nov 13 '05 #3

P: n/a
The problem is solved. The message body, which is missing, is
necessary. I do not know why but that solves the problem

Thanks everybody

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.