ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Add multiple excel worksheets(tabs) with jpgs (https://www.excelbanter.com/excel-worksheet-functions/21845-add-multiple-excel-worksheets-tabs-jpgs.html)

[email protected]

Add multiple excel worksheets(tabs) with jpgs
 
I have several jpgs that have to be inserted into each separate
worksheet. Is it possible to batch this along with naming the
worksheet tabs the jpg name?

Regards

Sunny


Jason Morin

This macro should do the job. Place all your .jpg files
into a new folder. Make sure to change "sPath" to your
path and correct folder name (mine is named "thejpgs").

Sub Insert_JPG()
Dim sPath As String
Dim NewWS As Worksheet
Dim PathArray As Variant
Dim FileName As String

sPath = "C:\Documents and Settings\jmorin\Desktop\thejpgs"

With Application.FileSearch
.NewSearch
.LookIn = sPath
.SearchSubFolders = False
.FileName = "*.*"
.FileType = msoFileTypeAllFiles

If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
PathArray = Split(.FoundFiles(i), "\")
FileName = PathArray(UBound(PathArray))
Set NewWS = Sheets.Add
ActiveSheet.Pictures. _
Insert (sPath & "\" & FileName)
NewWS.Name = FileName
Next
Else
MsgBox "There were no files found."
End If

End With

End Sub

---
HTH
Jason
Atlanta, GA

-----Original Message-----
I have several jpgs that have to be inserted into each

separate
worksheet. Is it possible to batch this along with

naming the
worksheet tabs the jpg name?

Regards

Sunny

.


[email protected]

Jason,

That worked wonders! Thanks a bunch!

Sunny



All times are GMT +1. The time now is 09:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com