Add multiple excel worksheets(tabs) with jpgs

  • Thread starter Thread starter SunnyHKim
  • Start date Start date
S

SunnyHKim

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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top