- 最後登錄
- 2024-9-17
- 在線時間
- 37 小時
- 註冊時間
- 2009-9-18
- 閱讀權限
- 20
- 精華
- 0
- UID
- 7034376
- 帖子
- 73
- 積分
- 22 點
- 潛水值
- 8184 米
| 分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。 這是依照你上個問題提供的檔案去修改的,看是否符合你所需。- Private Sub cmdMerge_Click()
- Dim fs As Object, fd As Object, f As Object, b As Boolean, s As String
-
- WorkName = Excel.ActiveWorkbook.Name '此檔案名稱
-
- i = 6
- Z = 1
-
- picHeight = Range("b1")
- picWidth = Range("b2")
- picColumn = Range("b3")
- picAngle = Range("b4")
-
- '將之前產生的圖片清除
- Sheet3.Activate
- Sheet3.Shapes.SelectAll
- Selection.Delete
- '建立FileSystemObject物件
- Set fs = CreateObject("Scripting.FileSystemObject")
-
- While Sheet1.Range("b" & i) <> ""
- Filepath = Sheet1.Range("a" & i)
- Filename = Sheet1.Range("b" & i)
- If Filepath = "" Then Filepath = Excel.Workbooks(WorkName).Path
- Filepath = IIf(Right(Filepath, 1) = "\", Filepath, Filepath & "\")
- '指定fd到Folder物件
- Set fd = fs.GetFolder(Filepath)
- '列舉出此資料夾所有檔案
- b = False
- For Each f In fd.Files
- If f.Name Like "*" & Filename Then
- Sheet3.Activate
- Sheet3.Range(picColumn & Z).Select
- Set shpPic = Excel.ActiveSheet.Shapes.AddPicture(f.Path, True, True, Selection.Left, Selection.Top, -1, -1)
- If picHeight > 0 Then
- shpPic.Height = 28.5 * picHeight
- '調整列高度
- Sheet3.Rows(Z).RowHeight = 28.5 * picHeight
- End If
- If picWidth > 0 Then shpPic.Width = 28.5 * picWidth
- shpPic.Rotation = picAngle
- Selection.Cut '2007才需要底下這樣作
- Sheet3.Range(picColumn & Z).Select
- ActiveSheet.Paste
- b = True
- Z = Z + 1
- End If
- Next
- If Not b Then s = s & Filepath & "資料夾裡面找不到符合 *" & Filename & "的檔案!" & vbCrLf
- i = i + 1 '讀取下一個名稱
-
- Wend
- MsgBox "執行完成" & IIf(s = "", "", vbCrLf & s)
- End Sub
複製代碼 ... |
|