2010 Excel Macro Not Working for Excel 2013

excelhelp6323

New Member
Joined
Mar 3, 2015
Messages
2
Hello,

A macro that I use to insert pictures of several items into cells at once is no longer working now that I am using Excel 2013. I have virtually no experience with coding, so any help is much appreciated. Here is the code:

Option Explicit
Sub AddItemPhoto()


Dim photoFolder
'Dim dbs As Database
'Dim rst As Recordset
'Dim wrkjet As Workspace
Dim ItemCol, PhotoCol, ItemColNo, PhotoColNo
Dim wksRange As Range
Dim firstRow, lastRow, I
Dim photoHight As Single, photoWidth As Single, rowH As Single, colW As Single
Dim photoRatioH As Single, photoRatioW As Single, photoRatio As Single
Dim strSQL

'TO Do: Change to the folder the photo files saved

photoFolder = "P:\images\IMAGES\"

ItemCol = InputBox("Column Index of ItemNo (ex. A,B,..):")
If ItemCol = "" Then Exit Sub
PhotoCol = InputBox("Column Index of Photo (ex. A,B,..):")
If PhotoCol = "" Then Exit Sub
firstRow = Int(InputBox("First Row Number:", , 2))
If firstRow = "" Then Exit Sub
lastRow = Int(InputBox("Last Row Number:", , ActiveCell.SpecialCells(xlLastCell).Row))
If lastRow = "" Then Exit Sub



ItemColNo = Asc(UCase(ItemCol)) - 64
PhotoColNo = Asc(UCase(PhotoCol)) - 64

Columns(PhotoCol).ColumnWidth = 20
colW = 84
For I = firstRow To lastRow
If InStr(Cells(I, ItemCol).Value, "/") > 0 Or InStr(Cells(I, ItemCol).Value, ":") > 0 Or InStr(Cells(I, ItemCol).Value, ".") > 0 Or InStr(Cells(I, ItemCol).Value, "*") > 0 Then
Else
If Dir(photoFolder & Trim(Cells(I, ItemColNo).Value) & ".jpg") <> "" Then
If Rows(I).RowHeight < 93.75 Then
Rows(I).RowHeight = 93.75
End If
rowH = Rows(I).RowHeight - 5
Cells(I, PhotoCol).Select

InsertPictureInRange photoFolder & Trim(Cells(I, ItemColNo).Value) & ".jpg", Cells(I, PhotoCol)
End If


End If
Next I
End Sub



Sub InsertPictureInRange(PictureFileName As String, TargetCells As Range)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
' determine positions
With TargetCells
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
' position picture
With p
.Top = t
.Left = l
.Height = h
.Width = w
If p.Height > h Then p.Height = h
End With
Set p = Nothing
End Sub


Sub DeletePictures()
'
' DeletePictures Macro
Dim Sh As Shape
Dim iSheetCount As Integer
Dim iSheet As Integer
Dim intOption


intOption = MsgBox("Are you sure you want to delete all of pictures in this sheet?", vbYesNo + vbDefaultButton2)
If intOption = vbNo Then
Exit Sub
End If

iSheetCount = ActiveWorkbook.Worksheets.Count
For iSheet = 1 To iSheetCount
With Worksheets(iSheet)
For Each Sh In .Shapes
If Sh.Type = msoPicture Or Sh.Type = 11 Then Sh.Delete


Next Sh
End With
Next iSheet

'

'
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
please explain what error(s) you are getting. I suspect it is an issue with 32bit vs 64bit
 
Upvote 0
please explain what error(s) you are getting. I suspect it is an issue with 32bit vs 64bit

That is probably it. The computer I was using before was 32 bit and now I am using 64 bit. The error message I am receiving is "Can't find project or library".

Thank you.
 
Upvote 0
Ahh, this is different than a 32bit/64bit issue. The project library isn't enabled on your newer excel version.
Get into any blank excel sheet on your newer version of Excel and press ALT+F11, select TOOLS/REFERENCES
Here you can see which libraries are enabled. Only you can determine which library is "missing". You may need to compare to your former version of Excel. Hope it helps..... oh P.S. in case you are thinking of just enabling them all :eeek: not advised as some libraries may conflict.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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