LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Run-time error 1004 with Range

Hi. I have these two subs to insert and delete drawing using command buttons,
but it doesn't seem to like how the Range is qualified here and causes
"run-time error 1004: application-defined or object-defined error".

I had a search in this forum, but still couldn't see what I've done wrong?
ps. I'm a VBA newbie...

Sam

Private Sub cbInsertImage_Click()
Const MY_PIC As String = "MyPic"
Dim MyWkSht As Worksheet
Dim ImageCell As Range
Dim rH As Double, rW As Double
Dim fH As Double, fW As Double
Dim fMod As Double
Dim v
Dim s As OLEObject

Set MyWkSht = ThisWorkbook.Worksheets("B1")
Set ImageCell = MyWkSht.Range("B11").MergeArea

ImageCell.Select

v = Application.GetOpenFilename("Drawing Files (*.dwg),*.dwg")
If v = False Then Exit Sub
If Dir(v) = "" Then Exit Sub

MyWkSht.Unprotect (1)

Set s = MyWkSht.OLEObjects.Add(Filename:=v, Link:=False,
DisplayAsIcon:=False)

On Error Resume Next
MyWkSht.OLEObjects(MY_PIC).Delete
On Error GoTo 0

rH = ImageCell.Height: rW = ImageCell.Width
fH = s.Height / rH
fW = s.Width / rW
fMod = IIf(fH fW, fH, fW)

With s
.Left = ImageCell.Left
.Top = ImageCell.Top
.Width = .Width / fMod
.Height = .Height / fMod
.Placement = xlMoveAndSize
.Name = MY_PIC
End With

With MyWkSht
.Hyperlinks.Add .Range("I32").MergeArea, v
.Range("I32").Font.Size = 8
.Range("I32").HorizontalAlignment = xlLeft
.Range("B10").Value = "Click DELETE button or CHANGE IMAGE button"
.Range("B32").Value = "Link to the above image" '**error 1004**
End With

cbInsertImage.Caption = "CHANGE IMAGE"
cbDeleteImage.Visible = True
cbDeleteImage.Enabled = True

MyWkSht.Protect (1)

End Sub


Private Sub cbDeleteImage_Click()

Const MY_PIC As String = "MyPic"
Dim MyWkSht As Worksheet
Dim Msg, Style, Title, Response, MyString
Dim s As String

Set MyWkSht = ThisWorkbook.Worksheets("B1")

MyWkSht.Unprotect (1)

Msg = "Are you sure to delete the image of the reference drawing?"
Style = vbYesNo + vbDefaultButton1
Title = "Warning"

Response = MsgBox(Msg, Style, Title)

If Response = vbYes Then
With MyWkSht
.Shapes(MY_PIC).Delete
.Range("B10").Value = "Click the INSERT IMAGE button"
.Range("B32").Value = "" '**error 1004**
.Range("I32").Value = "" '**error 1004**
End With

cbDeleteImage.Visible = False
cbInsertImage.Caption = "INSERT IMAGE"

Else

End If

MyWkSht.Protect (1)

End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
range.offset generates a Run Time error 1004 [email protected] Excel Programming 1 August 22nd 06 05:47 PM
Help! Run time error 1004, range of object_global failed in-over-his-head-bill Excel Programming 9 July 12th 06 05:46 AM
Button programming Run-time error '1004' with range El_Pablo[_3_] Excel Programming 2 April 4th 06 04:46 PM
Run-time error '1004' on Range.Activate Don Rouse Excel Programming 9 August 25th 05 04:05 PM
Run-time 1004 error on range select Morgan[_3_] Excel Programming 3 November 11th 03 11:44 PM


All times are GMT +1. The time now is 07:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"