| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4168 人关注过本帖
标题:如何将VB中计算的结果保存到Excel中
只看楼主 加入收藏
孙东东007
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2015-4-9
收藏
得分:0 
我试试,谢谢啦
2015-06-09 09:32
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
再给一段 合并 EXCEL 的代码参考吧。

程序代码:
Private Sub Command1_Click()

ExcelID.Visible = True          '显示EXCEL ,如果不用显示,这里就不显示
ExcelID.Caption = "应用程序调用 Microsoft Excel"            'EXECL 标题
ExcelID.Workbooks.Open (Text1.Text)        ' 打开文件
ExcelID.Worksheets.Item(1).Activate         '设置第一个工作表为活动工作表
Dim 起始位置 As Long
起始位置 = CLng(InputBox("请输入起始行号", "起始行号", 4))
Dim j As Long
    Dim i As Long
For j = 0 To List1.ListCount - 1
    openEID.Workbooks.Open (List1.List(j))          ' 打开文件
    openEID.Worksheets.Item(1).Activate         '设置第一个工作表为活动工作表
    For i = 1 To 79
        ExcelID.Cells(起始位置 + j, 坐标(i).NEWY) = openEID.Cells(坐标(i).OLDY, 坐标(i).OLDX)
    Next i
    openEID.Quit
    Call 进度条(j / (List1.ListCount - 1))
Next j
ExcelID.SaveWorkspace
ExcelID.Quit
End Sub


程序代码:
Call 置坐标(1, "67,3,31")
Call 置坐标(2, "66,7,30")
Call 置坐标(3, "5,3,4")
Call 置坐标(4, "6,5,4")
Call 置坐标(5, "57,5,22")
Call 置坐标(6, "4,7,3")
Call 置坐标(7, "44,7,17")
Call 置坐标(8, "33,3,14")
Call 置坐标(9, "35,7,14")
Call 置坐标(10, "34,5,14")
Call 置坐标(11, "50,3,20")
Call 置坐标(12, "65,5,30")
Call 置坐标(13, "12,5,7")
Call 置坐标(14, "59,5,23")
Call 置坐标(15, "60,3,28")
Call 置坐标(16, "9,5,6")
Call 置坐标(17, "15,5,8")
Call 置坐标(18, "17,3,9")
Call 置坐标(19, "25,3,11")
Call 置坐标(20, "27,3,12")
Call 置坐标(21, "26,5,11")
Call 置坐标(22, "62,3,29")
Call 置坐标(23, "43,5,17")
Call 置坐标(24, "64,3,30")
Call 置坐标(25, "16,7,8")
Call 置坐标(26, "3,5,3")
Call 置坐标(27, "56,3,22")
Call 置坐标(28, "41,7,16")
Call 置坐标(29, "38,7,15")
Call 置坐标(30, "24,7,10")
Call 置坐标(31, "21,5,10")
Call 置坐标(32, "18,5,9")
Call 置坐标(33, "61,7,28")
Call 置坐标(34, "70,3,27")
Call 置坐标(35, "73,4,27")
Call 置坐标(36, "76,5,27")
Call 置坐标(37, "79,6,27")
Call 置坐标(38, "82,7,27")
Call 置坐标(39, "14,3,8")
Call 置坐标(40, "36,3,15")
Call 置坐标(41, "37,5,15")
Call 置坐标(42, "69,3,26")
Call 置坐标(43, "72,4,26")
Call 置坐标(44, "75,5,26")
Call 置坐标(45, "78,6,26")
Call 置坐标(46, "81,7,26")
Call 置坐标(47, "29,7,12")
Call 置坐标(48, "51,5,20")
Call 置坐标(49, "55,7,21")
Call 置坐标(50, "7,7,4")
Call 置坐标(51, "8,3,6")
Call 置坐标(52, "40,5,16")
Call 置坐标(53, "42,3,17")
Call 置坐标(54, "39,3,16")
Call 置坐标(55, "49,5,19")
Call 置坐标(56, "58,3,23")
Call 置坐标(57, "28,5,12")
Call 置坐标(58, "30,3,13")
Call 置坐标(59, "2,3,3")
Call 置坐标(60, "45,3,18")
Call 置坐标(61, "53,3,21")
Call 置坐标(62, "52,7,20")
Call 置坐标(63, "48,3,19")
Call 置坐标(64, "47,7,18")
Call 置坐标(65, "20,3,10")
Call 置坐标(66, "10,7,6")
Call 置坐标(67, "11,3,7")
Call 置坐标(68, "46,5,18")
Call 置坐标(69, "13,7,7")
Call 置坐标(70, "63,7,29")
Call 置坐标(71, "54,5,21")
Call 置坐标(72, "19,7,9")
Call 置坐标(73, "31,5,13")
Call 置坐标(74, "32,7,13")
Call 置坐标(75, "68,3,25")
Call 置坐标(76, "71,4,25")
Call 置坐标(77, "74,5,25")
Call 置坐标(78, "77,6,25")
Call 置坐标(79, "80,7,25")


End Sub

Private Sub 置坐标(cs As Long, cs2 As String)

Dim fj() As String
    fj = Split(cs2, ",")
    坐标(cs).NEWY = fj(0)
    坐标(cs).OLDX = fj(1)
    坐标(cs).OLDY = fj(2)
End Sub

授人于鱼,不如授人于渔
早已停用QQ了
2015-06-09 09:34
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:0 
回复 9楼 孙东东007
程序代码:
Dim EXAPP As Excel.Application
Dim WB As Excel.Workbook
Dim sht As Excel.Worksheet

Private Sub Form_Load()
  Set EXAPP = CreateObject("excel.application")
  EXAPP.Visible = True
  Set WB = EXAPP.Workbooks.Open("文件路径及文件名")
  Set sht = WB.Worksheets("工作表名")
End Sub

Private Sub Form_Unload(Cancel As Integer)
  WB.Close
  Set sht = Nothing
  Set WB = Nothing
  Set EXAPP = Nothing
End Sub


大开眼界
2015-06-09 09:35
lypower
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-6-9
收藏
得分:0 
回复 8楼 孙东东007
就是你把打开excel的代码写到窗体加载模块中,按钮点击模块中只写数据保存代码
2015-06-09 09:47
快速回复:如何将VB中计算的结果保存到Excel中
数据加载中...
 
   



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

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