I've been using this code for months without any problems when suddenly, it stopped working and I really can't figure out what has changed because I didn't alter the code... I downloaded the latest Visual Studio's update and now it's not working... Anyways, it's for an Excel 2003 Macro that, when you click on the picture, allows you to select a new picture from your computer, resizes it to fit in a specific area, then gives the new picture the original code to do it all over again. Trouble is, it suddenly stopped working and I now get this error:
Run Time Error '1004':
Unable to set OnAction property of the Picture class
Here is the picture code:
Sub NewInsertMacro()
Dim myPictureName As Variant
Dim myPict As Picture
Dim myRng As Range
Dim myCurFolder As String
Dim myNewFolder As String
myCurFolder = CurDir
UnProtectSheet
YesNo = MsgBox("Do you want to delete the existing pic?", vbYesNo + vbCritical, "Hello")
Select Case YesNo
Case vbYes
ActiveSheet.Pictures.Delete
Case vbNo
MsgBox "The next picture you select will overlap the existing pic"
End Select
On Error Resume Next
ChDirNet myNewFolder
If Err.Number <> 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0
myPictureName = Application.GetOpenFilename _
(filefilter:="PictureFiles,*.jpg;*.bmp;*.tif;*.gif")
ChDirNet myCurFolder
If myPictureName = False Then
Exit Sub 'user hit cancel
End If
Range("BD17:CD42").Select
Set myRng = Selection.Areas(1)
Set myPict = myRng.Parent.Pictures.Insert(myPictureName)
myPict.Top = myRng.Top
myPict.Width = myRng.Width
myPict.Height = myRng.Height
myPict.Left = myRng.Left
myPict.Placement = xlMoveAndSize
myPict.OnAction = "'" & ThisWorkbook.Name & "'!NewInsertMacro"
ProtectSheet
End Sub
I didn't write this code. On debug, it tells me this is the error code: myPict.OnAction = "'" & ThisWorkbook.Name & "'!NewInsertMacro"
But like I said, it has worked for months, maybe even over a year without any issues, then suddenly when I download Visual Studios update since I upgraded from Express to the full version of Visual Studios, this code does not work and keep returning that error message. I tried selecting pictures from different areas, different type pictures, everything I can think of. I really don't have any idea what the problem might me. Any help much appreciated.
BTW, I posted this on VBForums, but so far they can't figure it out.
Bookmarks