?? 16310.html
字號:
<html>
<head>
<title>'Sheets' 方法 (_'Global'物件)失敗</title>
</head>
<body bgcolor="#FFFFFF" vlink="#808080">
<center>
<h1>'Sheets' 方法 (_'Global'物件)失敗</h1>
</center>
<hr size=7 width=75%>
<hr size=7 width=75%><p>
Posted by <a href="mailto:syshyan@ksts.seed.net.tw">有夢你會紅</a> on July 28, 1999 at 17:53:13:<p>
請問一下當我執行下面的程式碼....<br>我想利用EXCEL做圖表輸出...<br>第一次沒問題...不過再執行第二次<br>就會出現 'Sheets' 方法 (_'Global'物件)失敗...的訊息..<br>我真的都搞不好...請各位前輩幫我看一下...感激不盡...<p><br>'放1個CommandBox 和 1個OLE控制項<br>'專案→設定引用項目 ....中引用Excel的Object Library<br>'===============程式碼=====================<br>Option Explicit<br>Dim Excel_App As Excel.Application<br>Dim Excel_Sheet As Object<br>Dim Excel_Chart As Object<br>Private Sub Command1_Click()<br>'宣告設定使用EXCEL<br>Set Excel_App = CreateObject("Excel.Application")<br> Excel_App.Visible = True '顯示EXCEL<br> ' 判斷EXCEL的版本<br> Excel_App.Workbooks.Add (1)<br> Excel_App.ActiveSheet.Name = "報表"<br> If Val(Excel_App.Application.Version) >= 8 Then<br> Set Excel_Sheet = Excel_App.ActiveSheet<br> Else<br> Set Excel_Sheet = Excel_App<br> End If<br> '填入報表資料<br>With Excel_App<br> .Cells(1, 1) = "111"<br> .Cells(2, 1) = "323"<br> .Cells(3, 1) = "132"<br> .Cells(4, 1) = "165"<br> .Cells(5, 1) = "154"<br> .Cells(6, 1) = "145"<br> .Cells(7, 1) = "144"<br> .Cells(8, 1) = "155"<br> .Cells(9, 1) = "124"<br> .Cells(10, 1) = "231"<br> .Cells(1, 2) = "123"<br> .Cells(2, 2) = "621"<br> .Cells(3, 2) = "881"<br> .Cells(4, 2) = "411"<br> .Cells(5, 2) = "541"<br> .Cells(6, 2) = "151"<br> .Cells(7, 2) = "161"<br> .Cells(8, 2) = "451"<br> .Cells(9, 2) = "441"<br> .Cells(10, 2) = "611"<br> End With<br>Excel_App.Charts.Add<br>'sheet name<br>Excel_App.ActiveChart.Name = "圖表"<br>If Val(Excel_App.Application.Version) >= 8 Then<br> Set Excel_Chart = Excel_App.ActiveChart<br> Else<br> Set Excel_Chart = Excel_App<br> End If<br> Excel_Chart.ChartType = xlLine '使用折線圖<br> '設定圖表資料為sheet的A1到B10<br> Excel_Chart.SetSourceData Source:=Sheets("報表").Range("A1:B10"), PlotBy:= _<br> xlColumns<br> '開啟另一工作頁放圖表<br> Excel_Chart.Location Where:=xlLocationAsNewSheet<br> '儲存<br> Excel_App.ActiveWorkbook.Close True, FileName:=App.Path & "\Chart.xls"<br> Excel_App.Quit '關閉excel<br> '將剛剛儲存好的報表填入<br> Set Excel_Sheet = Nothing<br> Set Excel_Chart = Nothing<br> Set Excel_App = Nothing<br> OLE1.CreateEmbed App.Path & "\chart.xls"<br> End Sub<br>
<br>
<br><hr size=7 width=75%><p>
<a name="followups">Follow Ups:</a><br>
<ul><!--insert: 16310-->
</ul><!--end: 16310-->
<br><hr size=7 width=75%><p>
</body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -