標題:
置入圖片
[打印本頁]
作者:
Jared
時間:
2014-7-10 16:35
標題:
置入圖片
想請問大大
目前我在研究一個功能
如果資料夾裡面有N張圖片
我的Test頁籤畫面只有9格欄位
按下按鈕後程式會將相對應的圖片匯入(祥見圖片)
[attach]18672[/attach]
但是如果超過9格欄位
能不能自動複製相同的頁籤
再把剩下沒有放進去的圖片置入
我目前有手動嘗試過複製頁籤
但是Image命名不會變成 Image10~Image18
要怎麼樣才能解決目前的瓶頸><
希望能有神人指引我方向...
Private Sub CommandButton1_Click()
'----讀入圖片
If Dir(ThisWorkbook.Path & "\" & "Test" & "\1.jpg") <> "" Then
Image1.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\1.jpg")
Else
Image1.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
If Dir(ThisWorkbook.Path & "\" & "Test" & "\2.jpg") <> "" Then
Image2.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\2.jpg")
Else
Image2.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
If Dir(ThisWorkbook.Path & "\" & "Test" & "\3.jpg") <> "" Then
Image3.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\3.jpg")
Else
Image3.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
If Dir(ThisWorkbook.Path & "\" & "Test" & "\4.jpg") <> "" Then
Image4.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\4.jpg")
Else
Image4.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
If Dir(ThisWorkbook.Path & "\" & "Test" & "\5.jpg") <> "" Then
Image5.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\5.jpg")
Else
Image5.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
If Dir(ThisWorkbook.Path & "\" & "Test" & "\6.jpg") <> "" Then
Image6.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\6.jpg")
Else
Image6.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
If Dir(ThisWorkbook.Path & "\" & "Test" & "\7.jpg") <> "" Then
Image7.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\7.jpg")
Else
Image7.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
If Dir(ThisWorkbook.Path & "\" & "Test" & "\8.jpg") <> "" Then
Image8.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\8.jpg")
Else
Image8.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
If Dir(ThisWorkbook.Path & "\" & "Test" & "\9.jpg") <> "" Then
Image9.Picture = LoadPicture(ThisWorkbook.Path & "\" & "Test" & "\9.jpg")
Else
Image9.Picture = LoadPicture(ThisWorkbook.Path & "\white.jpg")
End If
End Sub
複製代碼
作者:
GBKEE
時間:
2014-7-12 14:21
回復
1#
Jared
附檔 看看
作者:
Jared
時間:
2014-7-14 15:09
回復
2#
GBKEE
附檔如下,內有10張圖片
希望能計算超過原本頁籤內的框架圖片
能另外新增相同架構的頁面置入剩下圖片
麻煩你了∼><
[attach]18694[/attach]
作者:
GBKEE
時間:
2014-7-15 18:24
本帖最後由 GBKEE 於 2014-7-15 18:29 編輯
回復
3#
Jared
試試看
Option Explicit
Sub Ex()
Dim i As Integer, R As Integer, C As Integer
Dim S As String
R = 10 '第10個 Image 列的位置
C = 1 '第10個 Image 欗的位置
With ActiveSheet
i = 10
On Error Resume Next
Do
.OLEObjects("Image" & i).Delete
i = i + 1
Loop Until Err <> 0
Err.Clear
On Error GoTo 0
S = Dir(ThisWorkbook.Path & "\Test\*.gif")
i = 0
Do While S <> ""
i = i + 1
If i <= 9 Then
.OLEObjects("Image" & i).Object.Picture = LoadPicture(ThisWorkbook.Path & "\Test\" & S)
Else
With .OLEObjects.Add(ClassType:="Forms.Image.1", Left:=.Cells(R, C).Left, Top:=.Cells(R, C).Top, Width:=.Cells(R, C).Resize(, 2).Width, Height:=.Cells(R, C).Resize(3).Height)
.Name = "Image" & i
.Object.Picture = LoadPicture(ThisWorkbook.Path & "\Test\" & S)
R = R
C = C + 2 'Image 有3欄(欄寬=2)
If C > 6 Then
C = 1
R = R + 3 'Image 有3列(列高=3列)
End If
End With
End If
S = Dir
Loop
i = i + 1
On Error Resume Next
Do
If i <= 9 Then
.OLEObjects("Image" & i).Object.Picture = LoadPicture("")
End If
i = i + 1
Loop Until Err <> 0
End With
End Sub
複製代碼
作者:
Jared
時間:
2014-7-16 10:19
回復
4#
GBKEE
感謝大大的協助
只是跟我想完成的有點不太一樣
昨天有寫了大致上的方向,可以執行
只是我程式在執行的時候
沒有採用判斷和迴圈的方式
以致於程式碼一堆...
最後沒辦法在第二頁更新圖片(如附檔)
[attach]18705[/attach]
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)