- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
11#
發表於 2012-12-9 14:04
| 只看該作者
回復 10# dafa
須是你說的:把所有CommandButton對應儲存格再存入對應的檔名才能解決 檔名存於Sheets("工作表1")裡才能如你所願
請修改GW4501表單UserForm_Initialize程式碼 如下- Option Explicit
- 'Public dw 'GW45011表單不須宣告: [Module1]模組已宣告過
- Public Sh As Worksheet '須新加公用變數 [TheButton] 模組才可引用
- Dim ButtonClass() As New TheButton
- Private Sub UserForm_Initialize()
- Dim E As Control, i As Integer
- Dim hWnd, tPath, oo
- GW4501.Height = Sheets("工作表3").Cells(3, 7) / 5
- GW4501.Width = Sheets("工作表3").Cells(3, 2) / 5
- hWnd = GetForegroundWindow
- tPath = ActiveWorkbook.Path & "\底圖\"
- 'tPath = Application.GetOpenFilename("EXCE檔(*.XLS),*xls")'
- [c1] = tPath
- oo = Dir(tPath)
- If oo = "" Then
- MsgBox "你底圖資料夾內沒放進圖檔"
- End
- Else
- [c2] = tPath & oo
- GW4501.Picture = LoadPicture(tPath & oo)
- End If
- 'ButtonClass變數設定為 New TheButton物件類別模組
- Set Sh = Sheets("工作表1") '工作表儲存圖表路徑
- With Sh
- For Each E In Me.Controls
- If InStr(E.Name, "CommandButton") Then
- i = i + 1
- ReDim Preserve ButtonClass(1 To i)
- Set ButtonClass(i).Button = E '指定 TheButton.Button(i) 的物件
- '*** CommandButton對應儲存格再存入對應的檔名 ***
- E.ControlTipText = Cells(i, "A").Address(0, 0) & ":"
- If Dir(.Cells(i, "A").Text) <> "" Then
- E.Picture = LoadPicture(.Cells(i, "A").Text)
- E.ControlTipText = E.ControlTipText & .Cells(i, "A")
- 'CommandButton的ControlTipText= .Cells(i, "A")的列名及內容(檔名)
- End If
- End If
- Next
- End With
- End Sub
複製代碼 請修改TheButton模組內- Option Explicit
- Public WithEvents Button As MSForms.CommandButton
- Private Sub Button_Click()
- Dim S
- S = Split(Button.ControlTipText, ":")
- If S(1) = "" Then
- Call 植物
- Button.Picture = LoadPicture(dw)
- Button.ControlTipText = Button.ControlTipText & dw
- S = Split(Button.ControlTipText, ":")
- GW4501.Sh.Range(S(0)) = dw
- 'CommandButton對應的儲存格存入: 檔名
- dw = ""
- End If
- End Sub
複製代碼 |
|