473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Macro to Insert Multiple Images to Multiple Sheet of an Excel Workbook

Hello Everyone,
Greetings to All.
I have some Issues in the below Macro.
My intention is to Copy/Insert the multiple Images in a folder that I select to the multiple sheets of a excel workbook.
The Macro should only have to insert the select images to the sheets.
The sheets are named as "Sheet1, Sheet2, Sheet3... etc..."
I want to insert 1st Image to Sheet1, 2nd Image to Sheet2, 3rd Image to Sheet3...............etc.
And Suppose if there are 20 Sheets in the workbook and I have 10 Images to insert it in Sheet1, Sheet2..........Sheet10, then I want to delete the remaining sheets(that is Sheet11, Sheet12.....Sheet20).
Also the Image should be fit in the range of I4 : S26
Currently I'm using the below Macro, But it is not working as per my need. All the selected images are beeing copied to the Active Sheet.
Could anyone write/modify the macro to the above said conditions.

Thanks in Advance.

Expand|Select|Wrap|Line Numbers
  1. Sub Insert_Picture ()
  2. Dim myPicture As Variant
  3. Dim myCell As Range
  4. Dim lLoop As Long
  5. Dim Sht As Worksheet
  6. Dim n As Integer
  7. On Error Resume Next
  8.     myPicture = Application.GetOpenFilename _
  9.         ("Pictures (*.gif; *.jpg; *.bmp; *.tif; *.png),*.gif; *.jpg; *.bmp; *.tif *.png", , "SELECT FILE(S) TO IMPORT", MultiSelect:=True)
  10.     If VarType(myPicture) = vbBoolean Then
  11.         MsgBox "NO FILES SELECTED"
  12.     Else
  13.     n = 1
  14.     If IsArray(myPicture) Then
  15.  
  16.  
  17.                 For lLoop = LBound(myPicture) To UBound(myPicture)
  18.  
  19.                 Sheets("Sheet(n)").Select
  20.                   With ActiveSheet
  21.                    Set myCell = .Range("I4:S26")
  22.                    .Pictures.Insert(myPicture(lLoop)).Select
  23.  
  24.                        With myCell
  25.                            Selection.Top = .Top
  26.                            Selection.Left = .Left
  27.                            Selection.Width = .Width
  28.                            Selection.Height = .Height
  29.                            Selection.Placement = xlMoveAndSize ' move and size with cells
  30.                        End With
  31.                    End With
  32.             n = n + 1
  33.             Next lLoop
  34.  
  35.        End If
  36. MsgBox "Copy Completed"
  37.     End If
  38.  
  39. End Sub
Sep 10 '14 #1
1 2394
twinnyfo
3,653 Expert Mod 2GB
Nimalan,

In line 19, try using this language:

Expand|Select|Wrap|Line Numbers
  1. Sheets(n).Select
or

Expand|Select|Wrap|Line Numbers
  1. Sheets("Sheet" & n).Select
I think the second is really what you may be after, but I think the first should also work as the sheets are understood in Excel to be sequential.

Hope this hepps.
Sep 10 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Pierre | last post by:
Hi, Tryin to use this method : MyExcelObject.Application.ActiveWorkBook.set_Colors(int index, object RHS). But really don't know what this RHS is ? Any ideas ? Thks for help
1
by: javzxp | last post by:
Hi I'd like to use C# to open an existing Excel workbook and save each worksheet it contains into a new Excel file. The name of each new Excel file should be the name of the worksheet copied...
1
by: Jerry J | last post by:
I am sending Excel reports to web clients. Excel opens in internet explorer displaying multiple sheets. It is pretty simple to do and works well. To do it, a client clicks a link to an ASPX page...
2
by: Sheshadrinath R | last post by:
Hello, I want to open an excel workbook, which is present in the server. I want to open this excel in the browser using ASP.NET. May I know, how can I do this? Will the File.Open() command work...
0
by: Tony2299 | last post by:
How to export data using ASP to excel workbook (with multiple worksheets)? I created an excel workbook with 5 worksheets and each one has a name range. Using asp I insert data to individual...
2
by: anujgupta | last post by:
In excel workbook we made one sheet in sheet 1 Part Qty Req Qty Recd A 5 5 When qty recd will equal to qty req entire row for part A should be trasfer...
3
by: mike11d11 | last post by:
I was able to create three worksheets in my workbook, but when I go to add the 4th I get an Invalid Index error. I must be leaving something out to when adding 4 or more sheets. Thanks Dim...
6
by: user033088 | last post by:
I have the following code which allows me to add the pdf files if I give the exact name and path of the file. But I have multiple pdf files in a folder which I want to add to each cell in the first...
0
by: kadishzm | last post by:
Hello All, Thanks for the help so far. I have been able to get a file working that allows dynamic field names to be selected by the user and run through a query. The last piece of the puzzle I am...
8
by: kw127533 | last post by:
I'm very new to Access and I'm trying to get multiple tables to export into a single Excel worksheet but have the data from each table on a separate tab. I am currently using this code that I found...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.