Import data with pictures

Dave_george

New Member
Joined
Jul 20, 2023
Messages
23
Office Version
  1. 2021
  2. 2016
  3. 2013
Platform
  1. Windows
Hello,

I am trying to import data that includes pictures saved in a separate folder. Each picture has its own excel workbook and are separately named. All the data saved in these files are in range A1:N32. I would like to import it when I specify the file name and press a button. Please see the attached picture.
 

Attachments

  • Import data with picture.JPG
    Import data with picture.JPG
    125.1 KB · Views: 3

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I have a good which opens up the correct workbook but I get a runtime error on line :

ThisWorkbook.Sheets("Sheet1").Range("A1:N32").PasteSpecial Paste:=xlPasteValues


VBA Code:
Sub ImportData()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim pictureName As String
    Dim picturePath As String
    
    ' Get the picture name from cell R2
    pictureName = ThisWorkbook.Sheets("Sheet1").Range("R2").Value
    
    ' Set the picture path
    picturePath = "C:\Users\Public\Pictures" & Range("R2").Text & ".xlsx"
    
    ' Open the workbook with the picture
    Set pictureWorkbook = Workbooks.Open(picturePath)
    
    ' Copy data from the picture workbook
    pictureWorkbook.Sheets(1).Range("A1:N32").Copy
    
    ' Paste data to the active sheet
    ThisWorkbook.Sheets("Sheet1").Range("A1:N32").PasteSpecial Paste:=xlPasteValues
    
    ' Close the picture workbook without saving
    pictureWorkbook.Close SaveChanges:=False
End Sub
 
Upvote 0
I have a good which opens up the correct workbook but I get a runtime error on line :

ThisWorkbook.Sheets("Sheet1").Range("A1:N32").PasteSpecial Paste:=xlPasteValues


VBA Code:
Sub ImportData()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim pictureName As String
    Dim picturePath As String
   
    ' Get the picture name from cell R2
    pictureName = ThisWorkbook.Sheets("Sheet1").Range("R2").Value
   
    ' Set the picture path
    picturePath = "C:\Users\Public\Pictures" & Range("R2").Text & ".xlsx"
   
    ' Open the workbook with the picture
    Set pictureWorkbook = Workbooks.Open(picturePath)
   
    ' Copy data from the picture workbook
    pictureWorkbook.Sheets(1).Range("A1:N32").Copy
   
    ' Paste data to the active sheet
    ThisWorkbook.Sheets("Sheet1").Range("A1:N32").PasteSpecial Paste:=xlPasteValues
   
    ' Close the picture workbook without saving
    pictureWorkbook.Close SaveChanges:=False
End Sub

After adding the below lines I get all the data with formatting but without the picture.

' Paste data to the active sheet
ThisWorkbook.Sheets("Sheet1").Range("A1:N32").PasteSpecial xlPasteAllMergingConditionalFormats
ThisWorkbook.Sheets("Sheet1").Range("A1:N32").PasteSpecial xlPasteRowHeights
ThisWorkbook.Sheets("Sheet1").Range("A1:N32").PasteSpecial xlPasteColumnWidths
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top