远程运行时,通过VBA刷新的电源查询失败

时间:2019-05-13 12:39:15

标签: excel vba powerquery

我的情况是这样的:

我必须安排一个每晚晚上在远程计算机上运行的xlsm文件,该文件基本上会打开30多个具有强大查询的excel文件,并在特定工作表上进行更新;这可以通过以下表达式实现:

            If SelectRow <> "" And SelectColumn<> "" Then
               Cells(SelectRow, SelectColumn).Select
            End If


                On Error Resume Next
                Selection.PivotTable.PivotCache.Refresh

                Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False


                DoEvents
                Application.CalculateUntilAsyncQueriesDone
                Application.Wait DateAdd("n", Esperar, Now)


        xlBook.Save
        xlBook.Close True

上述电源查询通过设置本地路径连接到同一台计算机上的excel文件和文件夹。

请注意,查询本身可以运行(如果手动运行)。我什至可以在打开远程会话的情况下运行一次该宏,但是当通过调度程序运行或关闭远程会话时,它们总是会失败。

代码将失败,并出现以下错误。有人可以建议吗?

非常感谢

************** Exception Text **************
Microsoft.Mashup.Client.UI.Shared.Com.ComWrapperException: Cannot cast null to type 'System.Double'. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.Mashup.Client.UI.Shared.Com.ComWrapper.As[T](Object value)
   --- End of inner exception stack trace ---
   at Microsoft.Mashup.Client.UI.Shared.Com.ComWrapper.As[T](Object value)
   at Microsoft.Mashup.Client.Excel.Com.ExcelComWrapper.AsIntFromDouble(Object value)
   at Microsoft.Mashup.Client.Excel.Com.ApplicationFeatures..ctor(IApplication application)
   at Microsoft.Mashup.Client.Excel.Com.Application..ctor(Object application, Boolean enableEvents)
   at Microsoft.Mashup.Client.Excel.AddIn.TryCreateApplication(Object appObject, IApplication& application)
   at Microsoft.Mashup.Client.Excel.AddIn.Extensibility.IDTExtensibility2.OnConnection(Object application, ext_ConnectMode connectMode, Object addInInst, Array& custom)

************** Exception Text **************
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Mashup.Host.Document.IApplicationConstants", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, Microsoft.Mashup.Host.Document.IApplicationConstants, is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:

  Resolving Microsoft.Mashup.Host.Document.IApplicationConstants,(none)
 ---> System.InvalidOperationException: The current type, Microsoft.Mashup.Host.Document.IApplicationConstants, is an interface and cannot be constructed. Are you missing a type mapping?
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context)
   at BuildUp_Microsoft.Mashup.Host.Document.IApplicationConstants(IBuilderContext )
   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
   --- End of inner exception stack trace ---
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
   at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
   at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T](IUnityContainer container, ResolverOverride[] overrides)
   at Microsoft.Mashup.Host.Document.DependencyInjectionService.Resolve[T]()
   at Microsoft.Mashup.Host.Document.ClientConfig.ClientConfigManager..ctor()
   at Microsoft.Mashup.Host.Document.ClientConfig.ClientConfigManager.get_Instance()
   at Microsoft.Mashup.Client.Excel.AddIn.Extensibility.IDTExtensibility2.OnDisconnection(ext_DisconnectMode disconnectMode, Array& custom)

0 个答案:

没有答案