?? 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">陳進(jìn)富</a> on May 29, 1998 at 01:02:43:<p>
In Reply to: <a href="2997.html"><b>當(dāng)然不對</b></a> posted by 小吳 on May 27, 1998 at 17:41:17:<p>
以下是我的講義中有關(guān)vb6 連上Excel <br>的范例,請注意xlApp,xlBook,xlSheet1的開啟及關(guān)閉順序<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 ' 可印前預(yù)視<br>' 可指定列印第N頁到第X頁<br> xlSheet1.PrintOut ' from page n ,to page n <br> xlApp.Quit ' ***** 使用完畢 一定要記得關(guān)閉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>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -