2017-03-06 19 views
1

エクセルシートで画像を取得するには、以下のvbaコードを使用していますが、このコードは画像をリンクとしてシートに追加しています。 。Excel VBA - シートにバルクイメージを挿入する

画像のリンクの代わりにシートに画像を添付するにはどうすればいいですか?

Sub AddOlEObject() 
    Dim mainWorkBook As Workbook 

    Set mainWorkBook = ActiveWorkbook 
    Sheets("Object").Activate 
    Folderpath = "C:\phoenix" 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    NoOfFiles = fso.GetFolder(Folderpath).Files.Count 
    Set listfiles = fso.GetFolder(Folderpath).Files 

    For Each fls In listfiles 
     strCompFilePath = Folderpath & "\" & Trim(fls.name) 
     If strCompFilePath <> "" Then 
      If (InStr(1, strCompFilePath, ".jpg", vbTextCompare) > 1) Then 
       counter = counter + 1 
       Sheets("Object").Range("A" & counter).Value = fls.name 
       Sheets("Object").Range("B" & counter).ColumnWidth = 50 
       Sheets("Object").Range("B" & counter).RowHeight = 150 
       Sheets("Object").Range("B" & counter).Activate 
       Call insert(strCompFilePath, counter) 
       Sheets("Object").Activate 
      End If 
     End If 
    Next 

End Sub 

Function insert(PicPath, counter) 
    'MsgBox PicPath 
    With ActiveSheet.Pictures.insert(PicPath) 
     With .ShapeRange 
      .LockAspectRatio = msoTrue 
      .Width = 100 
      .Height = 150 
     End With 
     .Left = ActiveSheet.Range("B" & counter).Left 
     .Top = ActiveSheet.Range("B" & counter).Top 
     .Placement = 1 
     .PrintObject = True 
    End With 
End Function 
+0

埋め込み画像を挿入するための[VBA]の重複可能性があります(http://stackoverflow.com/questions/17110425/vba-to-insert-embeded-picture-excel) –

答えて

0

イメージは、頻繁に使用する個人用ディレクトリに保存した単一のイメージですか?また、画像は.JPEGとして保存されますか?

下記の単純なVBAコードを使用してください。

Sub CALLPICTURE() 


Worksheets("SHEET1").Shapes.AddPicture Filename:="I:\Control\DECOMP\ Images\Zebra.jpg", linktofile:=msoFalse, _ 
      savewithdocument:=msoCTrue, Left:=0, Top:=0, Width:=632, Height:=136 


End Sub 

必要な数の画像を追加できます。

+0

バルク画像を取得する必要があるため動作しませんシート –

+0

はい、すべての画像に.jpgの拡張子が付いています –

関連する問題