- 帖子
- 36
- 主題
- 6
- 精華
- 0
- 積分
- 50
- 點名
- 0
- 作業系統
- windows xp
- 軟體版本
- office 2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2014-2-20
- 最後登錄
- 2015-3-6
|
9#
發表於 2014-4-7 22:58
| 只看該作者
回復 7# GBKEE
GBKEE 大:
感謝清楚的範例解決我的觀念問題 我也利用這個小例子改善我原先的程式碼
確實已經可以執行了 萬分感謝
以下也貼上我修改後的程式碼 讓有需要的人也可以學習
如果能讓程式碼更簡潔的話 也請其他大大指教
----------------------------------------------------------------------------------------------
Sub photoConv1()
Dim myFSO As New FileSystemObject
Dim myPath As String
Dim picNumRng As Range, myPic As Object
Dim myPhoto As String, countPhoto As String
Dim E As Variant
Dim i As Integer, j As Integer, k As Integer
myPath = ThisWorkbook.Path '確認活頁簿所在路徑
myPhoto = Dir(myPath & "\" & "原始相片" & "\" & "*.jpg") '圖片檔路徑
countPhoto = myFSO.GetFolder(myPath & "\" & "原始相片").Files.Count - 1 '取得相片數量
If myPhoto <> "" Then '資料夾中有相片時複製表格
j = 50
ActiveSheet.Cells(27, 3).Value = ActiveSheet.Cells(3, 3).Value
ActiveSheet.Cells(28, 7).Value = ActiveSheet.Cells(4, 7).Value
ActiveSheet.Cells(27, 7).Value = ActiveSheet.Cells(3, 7).Value
ActiveSheet.Cells(27, 8).Value = ActiveSheet.Cells(3, 8).Value
ActiveSheet.Cells(27, 10).Value = ActiveSheet.Cells(3, 10).Value
ActiveSheet.Cells(27, 12).Value = ActiveSheet.Cells(3, 12).Value
ActiveSheet.Cells(27, 14).Value = ActiveSheet.Cells(3, 14).Value
For i = 1 To ((countPhoto + 1) \ 2 - 1)
Rows("1:49").Copy '複製表格
ActiveSheet.Paste Cells(j, 1)
j = j + 49
Next i
For k = 1 To countPhoto
Set picNumRng = Range("A" & (25 * (k - 1) + 5 - Application.WorksheetFunction.RoundUp((k - 1) / 2, 0)))
picNumRng = k '輸入相片編號
For Each E In picNumRng
Set myPic = ActiveSheet.Pictures.Insert(myPath & "\" & "原始相片" & "\" & E & ".jpg") '插入與儲存格同名的相片檔
With myPic
.ShapeRange.LockAspectRatio = msoFalse
.Top = picNumRng.Offset(0, 1).Top
.Left = picNumRng.Offset(0, 1).Left
.Width = picNumRng.Offset(0, 1).MergeArea.Width
.Height = picNumRng.Offset(0, 1).MergeArea.Height
End With
Next
Next k
Else
MsgBox "資料夾中沒有相片"
End If
Set picNumRng = Nothing
Set myPic = Nothing
End Sub |
|