返回列表 上一主題 發帖

vba 如何修改新增公式 可以自動貼下一排

回復 1# Muffledsatyr


後學怕誤會意思,請問可以上傳範例嗎? 這樣比較容易了解,感謝。

TOP

回復 3# Muffledsatyr

請測試看看,謝謝
另外,有點不解就是你不是原來就有寫程式了嗎?


Sub InsertPictures()
'Update 20140513
Dim PicList() As Variant
Dim PicFormat As String
Dim Rng As Range
Dim sShape As Shape
On Error Resume Next
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
xColIndex = Application.ActiveCell.Column
If IsArray(PicList) Then
     xRowIndex = Application.ActiveCell.Row
     For lLoop = LBound(PicList) To UBound(PicList)
        If xColIndex > 5 Then xRowIndex = xRowIndex + 1: xColIndex = 1
        Set Rng = Cells(xRowIndex, xColIndex)
        Set sShape = ActiveSheet.Shapes.AddPicture(PicList(lLoop), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)
        xColIndex = xColIndex + 1
     Next
End If
End Sub

TOP

回復 5# Muffledsatyr

固定從A1 開始排列,請試看看,謝謝

Sub tt()
Dim PicList, PicFormat$, Rng As Range, sShape As Shape, i&, X%, Y%
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
X = 1 '從A1開始
If IsArray(PicList) Then
    For i = 1 To UBound(PicList)
        Y = Y + 1
        If Y > 5 Then X = X + 1: Y = 1   '5張-->換下一列
        Set Rng = Cells(X, Y)  '貼上照片的位置
        Set sShape = ActiveSheet.Shapes.AddPicture(PicList(i), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)
    Next
End If
End Sub

TOP

回復 12# Muffledsatyr

圖片高度5.79公分 寬度7.72公分有辦法加入嗎?
Set sShape = ActiveSheet.Shapes.AddPicture(PicList(i), msoFalse, msoCTrue, Rng.Left, Rng.Top, Rng.Width, Rng.Height)  
Rng.Width , Rng Height 可以直接改成你需要的數值如下,如果不改就是依照excel實際大小貼入
Set sShape = ActiveSheet.Shapes.AddPicture(PicList(i), msoFalse, msoCTrue, Rng.Left, Rng.Top, 7.72, 5.79)

TOP

回復 12# Muffledsatyr

請測試看看,不太了解是不是你要的結果,謝謝

Sub tt2()
Dim PicList, PicFormat$, Rng As Range, sShape As Shape, i&, X%, Y%
PicList = Application.GetOpenFilename(PicFormat, MultiSelect:=True)
X = 1
If IsArray(PicList) Then
    For i = 1 To UBound(PicList)
        Y = Y + 1
        If Y > 5 Then X = X + 1: Y = 1    '5張換下一列
        Set Rng = Cells(X, Y)
        Cells(X, Y).ColumnWidth = 42  '設定excel寬度
        Cells(X, Y).RowHeight = 170   '設定excel高度
        Set sShape = ActiveSheet.Shapes.AddPicture(PicList(i), msoFalse, msoCTrue, Rng.Left, Rng.Top, 7.72, 5.79)  '數字可設定照片寬高
    Next
End If
End Sub

TOP

回復 15# Muffledsatyr

請再測試看看,是不是您的需求,謝謝

圖片在Excel高度5.79公分 寬度7.72公分
下列程式碼需修改數值如下, 未來可自行修改所需
高度: 5.79 / 0.0353 = 164
寬度: 7.72 / 0.0353 = 219

Set sShape = ActiveSheet.Shapes.AddPicture(PicList(i), msoFalse, msoCTrue, Rng.Left, Rng.Top, 219, 164)  '數字可設定照片寬高

TOP

        靜思自在 : 知識要用心體會,才能變成自己的智慧。
返回列表 上一主題