首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

用VB向EXCEL表格中插入图片,却不行?报错:编译异常,未找到方法或数据成员

2012-07-08 
用VB向EXCEL表格中插入图片,却不行??报错:编译错误,未找到方法或数据成员.代码如下:Private Sub Command1_

用VB向EXCEL表格中插入图片,却不行??报错:编译错误,未找到方法或数据成员.
代码如下:
Private Sub Command1_Click()

  Dim xlApp As Excel.Application
  Dim xlBook As Excel.Workbook
  Dim xSheet As Excel.Worksheet
  Set xlApp = New Excel.Application
  Set xlBook = xlApp.Workbooks.Open("C:\Book1.xls ")
  Set xSheet = xBook.Worksheets(1)
  xlApp.Visible = True
  xSheet.Range("E10 ").Select '设置插入位置E列10行
  xSheet.Pictures.Insert("c:\LBN.JPG").Select '插入图片

  xSheet.Selection.ShapeRange.IncrementLeft -38.25 '可以设置图片位置
  xSheet.Selection.ShapeRange.IncrementTop -16.5
  xSheet.Selection.ShapeRange.ScaleWidth 0.77, msoFalse, msoScaleFromTopLeft '设置图片大小
  xSheet.Selection.ShapeRange.ScaleHeight 0.77, msoFalse, msoScaleFromTopLeft
  xlBook.Close False
  xlApp.Quit
  Set xlBook = Nothing
  Set xlApp = Nothing
End Sub
 在红色处报错..


我有一段在EXCEL中表格能实现正常的
  With Sheets(3).Pictures.Insert("D:\LBN.jpg ")
  .ShapeRange.LockAspectRatio = msoFalse
  .Placement = xlMoveAndSize
  .ShapeRange.Left = Range("a1 ").Left
  .ShapeRange.Top = Range("a1 ").Top
  .ShapeRange.Height = Range("a1:a2 ").Height
  .ShapeRange.Width = Range("a1:b1 ").Width
  End With

红色处提示:不扶持该类 不能解决...为何?

[解决办法]
试试看
Sheets(3).Pictures.Insert("D:\LBN.jpg ")
With Sheets(3).Selection
.ShapeRange.LockAspectRatio = msoFalse
.Placement = xlMoveAndSize
.ShapeRange.Left = Range("a1 ").Left
.ShapeRange.Top = Range("a1 ").Top
.ShapeRange.Height = Range("a1:a2 ").Height
.ShapeRange.Width = Range("a1:b1 ").Width
End With

热点排行