+ Reply to Thread
Results 1 to 3 of 3

Macro import images

Hybrid View

meccer Macro import images 11-08-2010, 06:21 AM
antoka05 Re: Macro import images 11-08-2010, 08:50 AM
meccer Re: Macro import images 11-08-2010, 09:21 AM
  1. #1
    Registered User
    Join Date
    11-08-2010
    Location
    South Africa
    MS-Off Ver
    Excel 2003
    Posts
    11

    Macro import images

    Hallo,

    I'm creating a reporting system in excel using macro's. What I've done so far is a csv file is imported, this contains an image name, images are imported using these image names. My problem is that all the images goes and sits on Cell A4, I want each image to import next to the image name.

    this is my code to import the images:
    Sub InsertPictures()
    Dim row As Long
    Dim picPath As String
    Dim Picture As Object
    Dim dHeight As Double
    Dim dWidth As Double
    
    row = 1
    
    On Error Resume Next
    
    While Cells(row, 1) <> ""
      Cells(row, 5).Select
      
      picPath = "D:\Asbestikum Design Files\Weekly Reports\Log & Slides\Slides\" + Cells(row, 4)
      ActiveSheet.Pictures.Insert(picPath).Select
      
      
      Set Picture = Selection
      'set cell height to picture size
      With Picture
      dWidth = .Width
      dHeight = .Height
     .Width = 100
     .Height = 75
     End With
    
      Picture.Top = Picture.TopLeftCell.Top
      Picture.Left = Picture.TopLeftCell.Left
      Picture.TopLeftCell.EntireRow.RowHeight = Picture.Height
      
      row = row + 1
    
    Wend
    End Sub

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Macro import images

    You could use this macro:

    Sub InsertPictures()
       Dim row As Long
       Dim picPath As String
       Dim Picture As Object
       Dim dHeight As Double
       Dim dWidth As Double
       Dim myImg As Object
       
       row = 1
       
       On Error Resume Next
       
       While Cells(row, 1) <> ""
         Cells(row, 5).Select
         
         'picPath = "D:\Asbestikum Design Files\Weekly Reports\Log & Slides\Slides\" + Cells(row, 4)
         picPath = "C:\documents and settings\44264520\desktop\" + Cells(row, 4)
         Set myImg = ActiveSheet.Pictures.Insert(picPath)
         
         
         'Set Picture = Selection
         'set cell height to picture size
         With myImg
           dWidth = .Width
           dHeight = .Height
           .Width = 100
           .Height = 75
         End With
       
         myImg.Top = ActiveCell.Top
         myImg.Left = ActiveCell.Left
         Rows(row).RowHeight = myImg.Height
         
         row = row + 1
       
       Wend
    End Sub
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    11-08-2010
    Location
    South Africa
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Macro import images

    Thanks Antonia

    Works perfect !!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1