2017-01-24 11 views
2

私はこの質問がいくつかの方法で複数回尋ねられていることを知っていますので、これが重複して表示された場合は重複としてマークしてください。Excelのセルに画像を挿入する

私はExcelで目録を作成したいと思います。セルに画像を挿入するには、すばやい方法が必要です。私はあなたがコメントを挿入することによってこれを行うことができますが、それはちょうど非常に遅いプロセスです。

これは、VBAや、フォルダの画像を目的のセルに追加するスクリプトで行うことができますか?

+2

これは良いスタートです。http://stackoverflow.com/questions/12936646/how-to-insert- a-picture-as-a-a-a-as-as-a-vbaを有する特定細胞位置である。しかし、どちらの写真がどのセルに移動するのかを特定する必要があります。これを行う方法はありますか? – R3uK

答えて

0

は、以下のコードを見てみましょう:

Public Sub sampleCode() 
Dim WB As Workbook 
Dim targetWS As Worksheet 
Dim targetCell As Range 
Dim imageCounter As Long 
Dim sourceFolderPath As String 
Dim dirStr As String 
Dim imageObj As Picture 

Set WB = ThisWorkbook 
Set targetWS = WB.Sheets(1) 

With Application.FileDialog(msoFileDialogFolderPicker) 
    .Title = "Select the folder that contains the pictures." 
    .Show 
    sourceFolderPath = .SelectedItems(1) & "\" 
End With 

dirStr = Dir(sourceFolderPath) 
Do Until dirStr = "" 
    If Right(dirStr, 3) = "png" Or Right(dirStr, 3) = "jpg" Then 
     imageCounter = imageCounter + 1 
     Set imageObj = targetWS.Pictures.Insert(sourceFolderPath & dirStr) 
     Set targetCell = targetWS.Range("A" & imageCounter) 
     With targetCell 
      .ColumnWidth = imageObj.Width/5.4636515404462 
      .RowHeight = imageObj.Height 
      imageObj.Top = .Top 
      imageObj.Left = .Left 
     End With 
    End If 
    dirStr = Dir 
Loop 

End Sub 

よろしく、 TheSilkCode

関連する問題