Board logo

標題: [發問] 有關Userform image [打印本頁]

作者: s13030029    時間: 2019-7-22 15:56     標題: 有關Userform image

目前這段程式是打開userform會自動匯入圖片
但是要怎樣修改才能判斷資料夾裡有檔案才匯入,沒檔案則跳出msgbox提醒找不到檔案

Private Sub UserForm_Initialize()
    Dim imgpath As String
    imgpath = ThisWorkbook.Path & "\" & "img"
    Image1.Picture = LoadPicture(imgpath & "\" & "123.jpg")
End Sub

[attach]31066[/attach]
作者: 准提部林    時間: 2019-7-22 19:43

Private Sub UserForm_Initialize()
    Dim imgpath As String
    imgpath = ThisWorkbook.Path & "\" & "img"
    if dir(imgpath & "\" & "123.jpg")="" then exit sub
    Image1.Picture = LoadPicture(imgpath & "\" & "123.jpg")
End Sub
作者: s13030029    時間: 2019-7-23 08:25

回復 2# 准提部林

這個方法可以~~~
不過已經找不到圖片了,要怎麼讓userform不再跳出來???

Private Sub UserForm_Initialize()
    imgname = ActiveWorkbook.Sheets(1).Range("A1").Value
    Dim imgpath As String
    imgpath = ThisWorkbook.Path & "\" & "img"
    If Dir(imgpath & "\" & imgname & ".jpg") = "" Then
        MsgBox ("找不到圖面!!!")
        Exit Sub
    End If
    Image1.Picture = LoadPicture(imgpath & "\" & imgname & ".jpg")
End Sub
作者: s13030029    時間: 2019-7-23 09:25

已解決~~~~
Sub 顯示圖面()
    imgname = ThisWorkbook.Sheets("製程模板").Range("I4").Value
    Dim imgpath As String
    imgpath = ThisWorkbook.Path & "\" & "圖面"  '指定資料夾
    If Dir(imgpath, vbDirectory) = "" Then MkDir imgpath
   
    If imgname = "" Then
        A = MsgBox("請先在計畫表輸入產品編號!!!", vbInformation, "提示訊息")
        Exit Sub
    Else
        If Dir(imgpath & "\" & imgname & ".jpg") = "" Then
            B = MsgBox("找不到圖面!!!,請確定圖面資料夾裡有該檔名", vbCritical, "提示訊息")
            Exit Sub
        Else
            圖面.Show 0
        End If
    End If
   
End Sub




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)