| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 381 人关注过本帖
标题:求大神帮忙,谢谢哈,程序报错,说类型不匹配。报错 说为定义 Set excels ...
只看楼主 加入收藏
yangfang577
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2014-3-11
结帖率:60%
收藏
已结贴  问题点数:20 回复次数:3 
求大神帮忙,谢谢哈,程序报错,说类型不匹配。报错 说为定义 Set excelsheet = excelbook.Worksheets("shee
Option Explicit

Dim excel As Application
Dim excelbook As Workbook
Dim excelsheet As Workbook
Dim x(1 To 4, 1 To 4) As Integer

Private Sub Command1_Click()
Randomize
Dim i, j As Integer
For i = 1 To 4
  For j = 1 To 4
    x(i, j) = 100 * Rnd()
  Next j
  Next i
  excel1.Range("a1:d4").Value = x
  excel1.Range("a1:d4").Select
  Set excelchart = excel.Charts.Add
  excelsheet.Application.Visible = True
  excelsheet.SaveAs App.Path + "\test.xls"

End Sub

Private Sub Form_Load()
Set excel = CreateObject("Excel.application")
Set excelbook = excel.Workbooks().Add
Set excelsheet = excelbook.Worksheets("sheet1")
End Sub

Private Sub form_unload(cancel As Integer)
excelsheet.Application.Quit
Set excelsheet = Nothing
End Sub

End Sub
搜索更多相关主题的帖子: excel 
2014-03-27 21:42
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
收藏
得分:20 
Dim excel As excel.Application
Dim excelbook As excel.Workbook
Dim excelsheet As excel.Worksheet   '在这里你定义错误,所以类型不匹配
Dim x(1 To 4, 1 To 4) As Integer

Private Sub Command1_Click()
Randomize
Dim i, j As Integer
For i = 1 To 4
  For j = 1 To 4
    x(i, j) = 100 * Rnd()
  Next j
  Next i
  excelsheet.Range("a1:d4").Value = x
  excelsheet.Range("a1:d4").Select
  Set excelchart = excel.Charts.Add
  excelsheet.Application.Visible = True
  excelsheet.SaveAs App.Path + "\test.xls"

End Sub

Private Sub Form_Load()
Set excel = CreateObject("Excel.application")
Set excelbook = excel.Workbooks.Add
Set excelsheet = excelbook.Worksheets.Add
End Sub

Private Sub form_unload(cancel As Integer)
Set excelsheet = Nothing
excel.Quit
End Sub
2014-03-27 22:18
w360989426
Rank: 5Rank: 5
等 级:职业侠客
威 望:4
帖 子:228
专家分:301
注 册:2013-11-12
收藏
得分:0 
版主正解
2014-03-27 22:24
yangfang577
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2014-3-11
收藏
得分:0 
谢谢大神
2014-03-28 10:22
快速回复:求大神帮忙,谢谢哈,程序报错,说类型不匹配。报错 说为定义 Set e ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.062190 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved