If FilePath = "" Then
FilePath = Excel.Workbooks(WorkName).Path
Else
If Right(FilePath, 1) = "\" Then
FilePath = FilePath
Else
FilePath = FilePath
End If
End If
txt = FilePath & "*" & Filename
File = Dir(txt)
Do While File <> ""
d(File) = ""
File = Dir()
Loop
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
End If
shpPic.Rotation = picAngle
Selection.Cut '2007才需要底下這樣作
Sheet3.Range(picColumn & Z).Select
ActiveSheet.Paste
Else
MsgBox "檔案:" & Fullpath & "不存在,請查看是否有拼錯字"
End If
i = i + 1 '讀取下一個名稱
Z = Z + 1
Exit For
Next
Wend
MsgBox "執行完成", vbOKOnly, ""
End Sub作者: tvmateiii 時間: 2018-8-1 07:41 PM
本帖最後由 tvmateiii 於 2018-8-1 07:42 PM 編輯
你應該自己嘗試看看捉臭蟲
提示你
找不到檔案的時候
是否要跳出迴圈呢
你的 For Next 有好好配對嗎
我實在看不懂
Exit For 在 Next 止面代表什麼意思
===========
Exit For
Next
Wend
MsgBox "執行完成", vbOKOnly, ""
End Sub
=========== 作者: Waroger 時間: 2018-8-3 05:13 PM
這是依照你上個問題提供的檔案去修改的,看是否符合你所需。
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