将控件名称作为字符串传递给VBA中的Form对象

时间:2019-06-25 21:42:42

标签: vba forms object

我将控件名称作为字符串传递到子控件中,因为该代码可以应用于许多窗体和控件以及子窗体控件。我无法弄清楚使用f窗体对象作为字符串传递时如何解决该控件。

  This works fine:
  Dim sControlName as string
  sControlName = "myControlName"
  Forms!myFormName.myChildFormName.Form(sControlName).Top = {some value}

  This will also work:
  Dim f as Form
  Set f = Forms!myFormName
  With f
      .myChildFormName.Form(sControlName).Top = {some value}
 End With

  This does not work:
  Dim f as Form
  Set f = Forms!myFormName.myChildFormName.Form
  With f
      'How do I get this below to work?
      (sControlName).Top = {some value}
  End With

1 个答案:

答案 0 :(得分:0)

经过反复试验,正确的构造方法是:

from datetime import datetime
from apscheduler.schedulers.background import BackgroundScheduler

def my_job(text):
    print(text)
def job1():
    now = datetime.datetime.now()
    sched = BackgroundScheduler()
    sched.add_job(my_job, 'date', run_date=now + 
datetime.timedelta(seconds = 20), args=['text'])
    sched.start()

def fun1():
    try:
        return "hello"
    finally:
        job1()
print fun1()