我不是一个强大的程序员(但试图成为一个强大的程序员)并且想知道是否有人有任何编写VBScript以打开Excel工作簿(在Application Server VM中)并执行ActiveX命令按钮(例如, commandbutton_Click())。
我一直打开Excel工作簿,但我坚持执行ActiveX命令按钮。
Option Explicit
'Dim pc, iMsg, iConf, Flds
Dim szHostName
Dim objExcel
Set objExcel = Wscript.CreateObject("Wscript.Shell")
'get the computer name
szHostName = objExcel.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
Call Test1()
Call SendAlertEmail(szHostName, "john.doe@corp.com", "test alert <no-reply@corp.com","Test E-mail Subject", "Test e-mail body")
objExcel.ActiveWorkbook.Close
objExcel.DisplayAlerts = False
objExcel.Application.Quit
'objExcel.DisplayAlerts = False
WScript.Echo "Finished."
WScript.Quit
'====================================================================================================
Public Sub Test1()
Dim objWorkbook
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("E:\testfolder\test.xlsm", 0, False)
objExcel.Application.Visible = True
objExcel.Application.Run "test.xlsm!Summary.cmdCycle_Click()"
End Sub
'/////////////////////////////////////////////
' --------------------------------------------------------------------------------- SendAlertEmail routine--------------------------------Start
Public Sub SendAlertEmail(ByVal servername, ByVal tostr, ByVal fromstr, ByVal subjectstr, ByVal bodystr)
Dim pc, iMsg, iConf, Flds
Set pc = CreateObject("Wscript.Network")
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
Dim emailBody
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "relay.exelonds.com"
Flds.Item(schema & "smtpserverport") = 25
Flds.Item(schema & "smtpauthenticate") = 0
Flds.Item(schema & "smtpusessl") = 0
Flds.Update()
With iMsg
.To = tostr
.From = fromstr
.Subject = servername & ":" & subjectstr
emailBody = bodystr
.HTMLBody = emailBody
.Sender = "Morning Report <noreply@corp.com>"
.Organization = "ABC Corporation"
.ReplyTo = "noreply@corp.com"
.Configuration = iConf
.Send()
End With
' Release Interfaces
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
End Sub
答案 0 :(得分:0)
我相信这应该有效:
Dim sheetName$
sheetName = "Name of your worksheet" '# MODIFY THIS LINE
xlBook.Application.run "'" & xlBook.Name & "'!" & sheetName & ".cmdCycle_Click"