Converting VBA to VBS file to use with .bat file to outlook email automation

eb101

Board Regular
Joined
Sep 25, 2014
Messages
62
I have a VBS code set to open, refresh all data connection, save and close all of my excel files and a .bat file that calls on that VBS code with task scheduler at 8:00 AM.

When I come in, I have a VBA in excel that I push when I come to work that sends those files to correct recipients. I cannot use task scheduler to send an email because of server restrictions (I already checked with IT and it was a dead end).

I am trying to see how do I convert the VBA to VBS so I can use a .bat file with task scheduler to circumvent the server restriction.

Sub Test()
Dim strLocation As String

Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail

''Change to Your Email Address
.To = "my email"
.CC = ""
.BCC = ""

''Add you own Subject and Message to the body
.Subject = "Email test to multiple email boxes"
.Body = "Hello World!"


''Update the path to match where your file is
strLocation = ("C:\Users\rock\Desktop\" & "Base.xlsx")
.Attachments.Add (strLocation)
.Display
.Send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With

End Sub

Any help would be appreciated.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I found a solution to this problem.


Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0)

objMail.Display 'To display message

objMail.to = ""
objMail.cc = ""
objMail.Subject = "Mail Subject"
objMail.Body = "This is Email Body"

objMail.Attachments.Add("C:\Users\w\Desktop\Base.xlsx")

objMail.Send

Set objMail = Nothing
Set objOutlook = Nothing
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top