How to run script in VBA On_Click event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I have a database of various scripts. Is there a way that I can launch
the Script contained in the "Script" textbox using the On_click event of a
run button?

Thank you,

Daniel
 
Not exactly sure what you are asking... My first thought is you would have
to place "=RunMyScript()" in the OnClick event of the Run button. Hope this
is what you were looking for.
 
Suppose I have the following in a MEMO field named "Script" in my form (which
contains vbscripts). I would like to know what vba code could be used in
conjunction with the on_click event to run the code.

******
Const xpRangeAutoFormatList2 = 8

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)
x=1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
For Each ObjItem in colItems
objWorksheet.Cells(x,1) = objItem.Name
objWorksheet.Cells(x,2) = objItem.DisplayName
objWorksheet.Cells(x,3) = objItem.State
x = x + 1
Next

Set objRange = objWorksheet.UsedRange
objRange.EntireColumn.Autofit()
objRange.Autoformat(xpRangeAutoFormatList2)
******
 
Not sure if this is possible. I believe the code has to exist at design time
so the compiler can verify syntax, check for errors, etc...
 
Back
Top