vb6 excel 实时错误‘91’对象变量或with块变量未设置

LIXIYO LIXIYO 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
一段代码\,实现的效果是:将几幅图片传入excel表格内,以供用户打印
下面程序目的是,取一幅图片放到excel表格内并使图片居中显示,
Public Sub CopyBmpOne(i As Integer)
With XlApp.Selection
dCellW = Selection.Width
' ' dCellW = XlSheet.Cells(5, 1).Selection.Height

dCellH = Selection.Height
' End With

Clipboard.Clear
Clipboard.SetData img1Show(i).Picture


XlSheet.PasteSpecial Format:="位图", Link:=False, DisplayAsIcon:=False
'ActiveSheet.Pictures.Insert(img1Show(0).Picture).Select

dPicW = Selection.ShapeRange.Width
dPicH = Selection.ShapeRange.Height
'重新定位
Selection.ShapeRange.IncrementLeft (dCellW - dPicW) / 2
Selection.ShapeRange.IncrementTop (dCellH - dPicH) / 2
End With
End Sub


我在使用过程中是反复调用的
XlSheet.Cells(5, 1).Select
Call CopyBmpOne(0)

XlSheet.Cells(5, 3).Select
Call CopyBmpOne(1)

XlSheet.Cells(5, 5).Select
Call CopyBmpOne(2)


XlSheet.Cells(5, 7).Select
Call CopyBmpOne(3)


第一次使用时没有问题,关闭退出,再打开也没问题。
当打开excel表格,再关闭表格,再次调用这段程序时就出错“实时错误‘91’对象变量或with块变量未设置”“实时错误‘91’对象变量或with块变量未设置”
为什么会出现这个问题呢?
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
LIXIYO
VB基础类 7,788 成员 197,583 内容