[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Setting Library Reference by code / Using CDOSYS in a .vbs file

Posted on 2011-05-12
2
Medium Priority
?
416 Views
Last Modified: 2012-05-11
Hello Experts,

I have the following code which is pretty simple and works in VB6, but when I copy it into a VBS file and comment out the 2 Form_Load lines I get the following error at line 22:

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

Also, in VB6 I can get the same error if I remove the reference to the Microsoft CDO Message library. I guess, my question should be how can I set a Reference to C:\windows\system32\cdosys.dll by code within my .vbs file?

Thank you,
'Option Explicit

Private Sub Form_Load() '**************COMMENT OUT FOR VBS******************
    Call testMail
End Sub '**************COMMENT OUT FOR VBS******************

Sub testMail()
    
    smtpServer = "smtpout.secureserver.net"
    smtpUser = "testing@m-p-c.org"
    smtpPass = "testing"
    fromAddress = "testing@m-p-c.org"
    
    toAddress = "aleks@aces-project.com"
    body = "testing"
    subject = "cdo test"
    
   
     Set cdoConfig = CreateObject("CDO.Configuration")
 
     With cdoConfig.Fields
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = smtpServer
        .Item(cdoSMTPAuthenticate) = 1
        .Item(cdoSendUsername) = smtpUser
        .Item(cdoSendPassword) = smtpPass
        '.Item("cdoSMTPServerPort") = 45
        .Update
    End With

 
    Set cdoMessage = CreateObject("CDO.Message")
 
    With cdoMessage
        Set .Configuration = cdoConfig
        
        .From = fromAddress
        .To = toAddress
        .subject = subject
        .HTMLBody = body
        
        .Send
    End With
 
    Set cdoMessage = Nothing
    Set cdoConfig = Nothing
    
    MsgBox "done."

End Sub

Open in new window

0
Comment
Question by:APD_Toronto
2 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 35751759
Try adding these constants to your code:
Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort = 2
Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic = 1
Const cdoAnonymous = 0
Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"

Regards,

Rob.
0
 

Author Closing Comment

by:APD_Toronto
ID: 35756755
THANK YOU
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question