- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 1# hong912
UserForm的程式碼- Option Explicit '在模組層次中強迫每個在模組�堛瘍僂くㄔ眸楨�確的宣告。
- Private Const 編號 = 3 '資料庫的欄位列號
- Private Const ThePicture = "d:\ttt.gif" '設立匯出圖片的路徑檔名
- Dim Ar(10), Sh As Worksheet
- 'Dim Ar()
- Private Sub UserForm_Initialize() '表單初始化的預設事件程序
- Dim I As Integer
- Set Sh = Sheets("Sheet1") '資料庫的工作表
- With Sh
- ComboBox1.List = .Range("a4", .[a4].End(xlDown)).Value '指定 ComboBox1的內容
- End With
- 'Dim Ar()時可用下式
- 'Ar = Array(TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, TextBox7, TextBox8, TextBox9, TextBox10, TextBox11)
- For I = 0 To UBound(Ar)
- Set Ar(I) = Me.Controls("TextBox" & I + 1) '陣列的元素設為TextBox (物件)
- Next
- Image1.PictureSizeMode = fmPictureSizeModeStretch
- '參數fmPictureSizeModeStretch= 1 :調整圖片大小以填滿表單或活頁,此設定會造成圖片的水平與垂直方向比例被扭曲。
- End Sub
- Private Sub ComboBox1_Change()
- Dim Sp As Picture, I As Integer
- If ComboBox1.ListIndex > -1 Then '選擇 ComboBox1的內容
- For I = 0 To UBound(Ar)
- Ar(I).Text = Sh.Cells(編號 + ComboBox1, I + 2)
- Next
- End If
- With Sh
- For Each Sp In .Pictures '尋找N欄中的圖片,複製之
- If Sp.TopLeftCell.Address(0, 0) = "N" & 編號 + ComboBox1 Then Sp.Copy: Exit For
- Next
- '利用圖表匯出存檔
- With .ChartObjects.Add(1, 1, Sp.Width, Sp.Height) '新增 圖表
- .Chart.Paste '貼上 圖片
- .Chart.Export Filename:=ThePicture '匯出 圖片
- .Delete '刪除 圖表
- End With
- End With
- Image1.Picture = LoadPicture(ThePicture) 'Image1 指定圖片
- End Sub
- Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) '表單絕束時 預設事件程序
- If Dir(ThePicture) <> "" Then Kill ThePicture '刪除 匯出的圖片
- End Sub
複製代碼 |
|