- 帖子
- 14
- 主題
- 2
- 精華
- 0
- 積分
- 17
- 點名
- 0
- 作業系統
- windows7
- 軟體版本
- office2010
- 閱讀權限
- 10
- 性別
- 男
- 註冊時間
- 2014-10-22
- 最後登錄
- 2018-7-24
|
UsedRange 此物件代表指定工作表中的已用範圍
所以當工作表中已有資料時,
並不一定是抓 A欄 ,D欄 ,G欄, ...
luhpro 發表於 2014-11-4 23:49 
謝謝大大回覆..
剛才試用了一下大大建議的程式碼..
出現了 "型態不符合" 的錯誤訊息耶...可否再指點一二呢?- Option Explicit
- Sub ChangeSize()
- Dim Mypath As String, E As Range, i As Integer ', MyPic As Object
- Mypath = "\C:\Users\leon\Desktop\Test\"
- With Sheets("照片索引")
- .Pictures.Delete
- For i = 1 To 7 Step 3 'A欄 ->1,D欄 ->4,G欄 ->7
-
- For Each E In .Cells.Columns(i) ' 'A欄 ->1,D欄 ->4,G欄 ->7
-
- E.ColumnWidth = 25 '調整儲存格寬度
- E.RowHeight = 50 '調整儲存格高度
-
- If Dir(Mypath & E & ".jpg") <> "" Then
- 'Set MyPic = ActiveSheet.Pictures.Insert(Mypath & E & ".jpg")
- With .Pictures.Insert(Mypath & E & ".jpg")
- .ShapeRange.LockAspectRatio = msoFalse
- .Left = E.Cells(1, 2).Left
- .Top = E.Cells(1, 2).Top
- .Width = E.Cells(1, 2).Width '=儲存格寬度
- .Height = E.Cells(1, 2).Height '=儲存格高度
- End With
- End If
- Next
- Next
- End With
- End Sub
複製代碼 |
|