Excel 2016和后期绑定的活动X错误

时间:2016-12-31 06:07:00

标签: excel vba excel-vba access-vba office365

我在我的电脑上安装了Microsoft Office 365 Business并尝试运行Access VBA来创建Excel对象。这是我正在使用的Access VBA语法

Dim xl As Object, wb As Object, ws As Object, ch As Object

Set xl = CreateObject("Excel.Application")

然而,它会点击CreateObject行并在下面显示图片,但在运行Office 365 Business的PC上。如果我在运行Office 2010的计算机上运行相同的语法,它将完全按照预期执行并创建Excel对象错误。

为了能够使用Microsoft Office 365 Business运行此语法,我必须更改哪些内容?

Error Message

修改
这是我看到的唯一注册表项 - 它很接近,但不完全是评论中所述的内容 Registry Key

1 个答案:

答案 0 :(得分:1)

一种选择是在尝试呼叫implicit val seqInstance = new MonadFilter[Seq] with Traverse[Seq] { def traverse[G[_] : Applicative, A, B](fa: Seq[A])(f: (A) ⇒ G[B]): G[Seq[B]] = fa match { case head +: tail ⇒ f(head).map2(traverse(tail)(f))(_ +: _) case _empty ⇒ Seq.empty[B].pure[G] } def foldLeft[A, B](fa: Seq[A], b: B)(f: (B, A) ⇒ B): B = fa.foldLeft(b)(f) def foldRight[A, B](fa: Seq[A], lb: Eval[B])(f: (A, Eval[B]) ⇒ Eval[B]): Eval[B] = fa match { case head +: tail ⇒ f(head, foldRight(tail, lb)(f)) case _empty ⇒ lb } def pure[A](x: A): Seq[A] = Seq(x) def empty[A]: Seq[A] = Seq.empty[A] def flatMap[A, B](fa: Seq[A])(f: (A) ⇒ Seq[B]): Seq[B] = fa.flatMap(f) def tailRecM[A, B](a: A)(f: (A) ⇒ Seq[Either[A, B]]): Seq[B] = { @tailrec def go(seq: Seq[Either[A, B]]): Seq[B] = if (seq.contains((_: Either[A, B]).isLeft)) go(seq.flatMap { case Left(a) ⇒ f(a) case b ⇒ Seq(b) }) else seq.collect { case Right(b) ⇒ b } go(Seq(Left(a))) } override def mapFilter[A, B](fa: Seq[A])(f: (A) ⇒ Option[B]): Seq[B] = fa.flatMap(f(_).toSeq) } 之前检查CLSID是否存在。您可以使用ole32.dll函数import cats.{MonadState, Foldable, Functor} import cats.instances.option._ import cats.syntax.foldable._ import cats.syntax.functor._ import cats.syntax.functorFilter._ import monocle.macros.Lenses @Lenses case class Pos(x: Int, y: Int) sealed abstract class Dir(val cmd: Pos ⇒ Pos) case object South extends Dir(Pos.y.modify(_ - 1)) case object North extends Dir(Pos.y.modify(_ + 1)) case object East extends Dir(Pos.x.modify(_ + 1)) case object West extends Dir(Pos.x.modify(_ - 1)) @Lenses case class PosAndDir(pos: Pos, dir: Dir) val clockwise = Vector(North, East, South, West) val right: Map[Dir, Dir] = clockwise.zip(clockwise.tail :+ clockwise.head).toMap val left: Map[Dir, Dir] = right.map(_.swap) sealed abstract class Instruction(val cmd: PosAndDir ⇒ PosAndDir) case object TurnLeft extends Instruction(PosAndDir.dir.modify(left)) case object TurnRight extends Instruction(PosAndDir.dir.modify(right)) case object Walk extends Instruction(pd ⇒ PosAndDir.pos.modify(pd.dir.cmd)(pd)) def runInstructions[F[_] : Foldable : Functor](instructions: F[Instruction])(start: PosAndDir): PosAndDir = instructions.map(i => State.modify(i.cmd)).sequence_.runS(start).value 对其进行测试(VBA内部也用于CreateObjectCLSIDFromString次调用):

CreateObject

您可以将其包装在一个简单的“存在”测试中,如下所示:

GetObject

这使您可以在尝试创建它们之前测试类(并避免使用错误处理程序来捕获错误的CLSID):

'Note, this is the 32bit call - use PtrSafe for 64bit Office.
Private Declare Function CLSIDFromString Lib "ole32.dll" _
    (ByVal lpsz As LongPtr, ByRef pclsid As LongPtr) As Long