clintster62
New Member
- Joined
- May 5, 2022
- Messages
- 3
- Office Version
- 2021
- 2016
- Platform
- Windows
The variable to pass is EMailVar
Q: need to know how to setup vbs to receive variable
Option Explicit
' create a vbs script to receive a variable parameter and send email.
'run vbs script by passing variable
'wait for process to complete
'kill script
Sub writeVBScript()
Dim s As String
Dim SFilename As String
Dim intFileNum As Integer
Dim wshShell As Object
Dim proc As Object
Dim EMailVar As String
Dim ProcName As String
Dim VBScriptName As String
VBScriptName = "\EMailVBScript.vbs"
'write VBScript (Writes to Excel Sheet1!A1 & Calls Function Module1.ReturnVBScript)
s = ""
s = s & "Set olApp = CreateObject(""WScript.Shell"")" & vbCrLf
s = s & "olApp.Run ""outlook.exe /recycle"", 1, False" & vbCrLf
s = s & "Set CIApp = CreateObject(""Outlook.Application"")" & vbCrLf
s = s & "Set CIMessage = CIApp.CreateItem(0)" & vbCrLf
s = s & "dim EMailVar"
s = s & "With CIMessage" & vbCrLf
s = s & " .To = " & EMailVar & vbCrLf
s = s & " .Subject = ""Email test "" " & vbCrLf
s = s & " .HTMLBody = ""Message Body goes here "" " & vbCrLf
s = s & "End With" & vbCrLf
s = s & "CIMessage.Send" & vbCrLf
Debug.Print s
' Write VBScript file to disk
SFilename = ActiveWorkbook.Path & VBScriptName
intFileNum = FreeFile
Open SFilename For Output As intFileNum
Print #intFileNum, s
Close intFileNum
DoEvents
'run VBScript file and pass one variable
EMailVar = "Test_Address@gmail.com"
ProcName = "cscript " & SFilename & " " & EMailVar
Set proc = wshShell.Exec(ProcName) 'run VBScript passing variables
'Wait for script to end
Do While proc.Status = 0
DoEvents
Loop
Kill ActiveWorkbook.Path & VBScriptName
End Sub
Thanks in advance for all assistance.
Q: need to know how to setup vbs to receive variable
Option Explicit
' create a vbs script to receive a variable parameter and send email.
'run vbs script by passing variable
'wait for process to complete
'kill script
Sub writeVBScript()
Dim s As String
Dim SFilename As String
Dim intFileNum As Integer
Dim wshShell As Object
Dim proc As Object
Dim EMailVar As String
Dim ProcName As String
Dim VBScriptName As String
VBScriptName = "\EMailVBScript.vbs"
'write VBScript (Writes to Excel Sheet1!A1 & Calls Function Module1.ReturnVBScript)
s = ""
s = s & "Set olApp = CreateObject(""WScript.Shell"")" & vbCrLf
s = s & "olApp.Run ""outlook.exe /recycle"", 1, False" & vbCrLf
s = s & "Set CIApp = CreateObject(""Outlook.Application"")" & vbCrLf
s = s & "Set CIMessage = CIApp.CreateItem(0)" & vbCrLf
s = s & "dim EMailVar"
s = s & "With CIMessage" & vbCrLf
s = s & " .To = " & EMailVar & vbCrLf
s = s & " .Subject = ""Email test "" " & vbCrLf
s = s & " .HTMLBody = ""Message Body goes here "" " & vbCrLf
s = s & "End With" & vbCrLf
s = s & "CIMessage.Send" & vbCrLf
Debug.Print s
' Write VBScript file to disk
SFilename = ActiveWorkbook.Path & VBScriptName
intFileNum = FreeFile
Open SFilename For Output As intFileNum
Print #intFileNum, s
Close intFileNum
DoEvents
'run VBScript file and pass one variable
EMailVar = "Test_Address@gmail.com"
ProcName = "cscript " & SFilename & " " & EMailVar
Set proc = wshShell.Exec(ProcName) 'run VBScript passing variables
'Wait for script to end
Do While proc.Status = 0
DoEvents
Loop
Kill ActiveWorkbook.Path & VBScriptName
End Sub
Thanks in advance for all assistance.