从访问程序中操纵excel范围 [英] manipulating excel range from an access program

查看:79
本文介绍了从访问程序中操纵excel范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用"with selection"和"end with"操作来自访问程序的excel中的范围选择时,程序会运行一次,然后当我再次运行时挂起;我需要结束声明不同?


 


    XLAPP.Application.Range(Selection,Selection.End(xlToRight))。选择

   使用XLAPP.Selection

        .Horizo​​ntalAlignment = 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))
.Horizo​​ntalAlignment = 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)).Select

the 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆