📄 3012.html
字号:
<html>
<head>
<title>范例: vb6 连上Excel </title>
</head>
<BODY BACKGROUND="" BGCOLOR="white" TEXT="black" LINK="red" VLINK="#808080" ALINK="">
<center>
<h1>范例: vb6 连上Excel </h1>
</center>
<HR><p>
Posted by <a href="mailto:albertcfchen@gvc.com">陈进富</a> on May 29, 1998 at 01:02:43:<p>
In Reply to: <a href="2997.html"><b>当然不对</b></a> posted by 小吴 on May 27, 1998 at 17:41:17:<p>
以下是我的讲义中有关vb6 连上Excel <br>的范例,请注意xlApp,xlBook,xlSheet1的开启及关闭顺序<p>范例: vb6 连上Excel <p>Private Sub XlsTest()<br> Dim xlApp As EXCEL.Application ‘ 注意要先按装 Excel (建议使用Office97以上版本)<br> Dim xlBook As EXCEL.Workbook<br> Dim xlSheet1 As EXCEL.Worksheet<br> Dim SQL As String<br> Dim xlsFile As String<br> <br> xlsFile = App.Path & "\test1.xls"<br> <br>‘ 以下作法 即为 “ OLE Automation “<br> Set xlApp = CreateObject("EXCEL.APPLICATION")<p> ' Set xlBook = xlApp.Workbooks.Add ‘ 新增<br> ' Set xlSheet1 = xlApp.Sheets(1) ' 相同<p> Set xlBook = xlApp.Workbooks.Open(xlsFile) ‘ 开启已存在的XLS档 <br> Set xlSheet1 = xlBook.Worksheets(1) ‘ 指定WorkSheet<br> <br> xlApp.Visible = True ' 若不需显示Excel 画面 -->False<br>' 存资料至指定的位置 (列,行)<br> xlSheet1.Cells(1, 1).Value = "AA"<br> xlSheet1.Cells(1, 2).Value = "BB"<br> xlSheet1.Cells(1, 3).Value = "CC"<p> xlSheet1.Cells(2, 1).Value = 1<br> xlSheet1.Cells(2, 2).Value = 2<br> xlSheet1.Cells(2, 3).Value = 3<br> <br> xlSheet1.Cells(3, 1).Value = 10<br> xlSheet1.Cells(3, 2).Value = 20<br> xlSheet1.Cells(3, 3).Value = 30<br> ' Row, Col<br> On Error Resume Next<p> xlSheet1.Application.SaveWorkspace ' 储存Current WorkSheet<p>' xlSheet1.PrintPreview ' 可印前预视<br>' 可指定列印第N页到第X页<br> xlSheet1.PrintOut ' from page n ,to page n <br> xlApp.Quit ' ***** 使用完毕 一定要记得关闭Excel程式<br>' Release memory<br> Set xlSheet1 = Nothing<br> Set xlBook = Nothing<br> Set xlApp = Nothing<p>End Sub<br>
<br>
<p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 3012-->
</ul><!--end: 3012-->
<br><HR><p>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -