从访问程序中操纵excel范围 [英] manipulating excel range from an access program
问题描述
当使用"with selection"和"end with"操作来自访问程序的excel中的范围选择时,程序会运行一次,然后当我再次运行时挂起;我需要结束声明不同?
XLAPP.Application.Range(Selection,Selection.End(xlToRight))。选择
使用XLAPP.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.Orientation = 90
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
结束
在行
XLAPP。 Application.Range(Selection,Selection.End(xlToRight))。选择单词Selection不引用Excel应用程序对象,因此它可能会创建一个新的Excel实例这不受您的申请控制。当您自动化另一个应用程序时,您必须非常小心地让该应用程序的所有对象
引用您创建的对象变量。使用XLAPP。范围(XLAPP.Selection,XLAPP.Selection.End(xlToRight))
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.Orientation = 90
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End with
when manipulating a range selection in excel from an access program using the 'with selection' and 'end with' the program works once then hangsup when I run a second time; do I need to end the with statement differently?
XLAPP.Application.Range(Selection, Selection.End(xlToRight)).Select
With XLAPP.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.Orientation = 90
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
In the line
XLAPP.Application.Range(Selection, Selection.End(xlToRight)).Selectthe word Selection does not refer to the Excel application object, so it probably creates a new instance of Excel that is not controlled by your application. When you automate another application, you must take great care to let ALL objects of that application refer to the object variable that you create.
With XLAPP.Range(XLAPP.Selection, XLAPP.Selection.End(xlToRight)) .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .Orientation = 90 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With
这篇关于从访问程序中操纵excel范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!