Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default " Select method of range class failed" if sheet not on top

Dim Pict As Object
Dim p As Object
Filename$ = "C:\aScopePic\jdpic7.png"
DoThis$ = "c:\windows\wgetbin\wget.exe -t1 -O"
DoThis$ = DoThis$ + "C:\aScopePic\jdpic8.png"
DoThis$ = DoThis$ + " 10.32.54.19/Image.png"
If Dir(Filename$) = "" Then Stop
ret = Shell(DoThis$):
' Works so far, pic saved locally
' Now the following works ONLY if the Effic tab was on top when I run
the VBA
' Otherwise the next line returns " Select method of range class
failed"
Worksheets("Effic").Range("B3:F18").Select
Worksheets("Effic").Range("B3:F18").Activate
ActiveSheet.Pictures.Insert (Filename$)
' I would like to be able to insert the picture onto any of the
sheets
' THANK YOU !!!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default " Select method of range class failed" if sheet not on top

Hi
Never activate if you don't have to

Worksheets("Effic").Range("B3:F18").Pictures.Inser t (Filename$)

will probably work if the code worked originally with the sheet on
top.
Not checked though.
regards
Paul

On May 14, 6:50*am, jad700 wrote:
Dim Pict As Object
Dim p As Object
Filename$ = "C:\aScopePic\jdpic7.png"
DoThis$ = "c:\windows\wgetbin\wget.exe *-t1 -O"
DoThis$ = DoThis$ + "C:\aScopePic\jdpic8.png"
DoThis$ = DoThis$ + " 10.32.54.19/Image.png"
If Dir(Filename$) = "" Then Stop
ret = Shell(DoThis$):
' Works so far, pic saved locally
' Now the following works ONLY if the Effic tab was on top when I run
the VBA
' Otherwise the next line *returns " Select method of range class
failed"
Worksheets("Effic").Range("B3:F18").Select
Worksheets("Effic").Range("B3:F18").Activate
ActiveSheet.Pictures.Insert (Filename$)
' I would like to be able to insert the picture onto any of the
sheets
' THANK YOU !!!!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default " Select method of range class failed" if sheet not on top

Many thanks Avi and Paul
I got that fixed last night, but now have several more questions.
----
Q1
I use lines like
Sheet4.Cells(8, CurColSh4%) = "XYZ" and
Sheet4.Cells.ClearContents
extensively through my code, but I am concerned that the order of the
worksheets might change and would be a disaster.
I think I would like to use
Sheet("Effic").Cells(8, CurColSh4%) = "XYZ" but do not know the
right syntax.
----
Q2
The buttons I have made move around when running, specifically one
moves on top of the other. How can I lock their location.
---
Q3 the file size just keeps getting bigger, currently 5 meg for a 1000
line program,
even if I clear contents of the sheets. How can I fix this ?
---
Q4 - How can I get the current Worksheet and location (Range) as
variables, so I can jump back to them.
---
Optional -
Why Never activate if you don't have to? What is the difference
between activate and select.?
---
By the way, to fix it I used
' Store the pic on the Picts tab
Worksheets("Picts").Activate
Worksheets("Picts").Range("F5").Activate
ActiveSheet.Pictures.Insert (Filename$)
Worksheets("AllData").Activate
( Sorry Paul, I will go back and try your line of code )
-----
THANKS !!

On May 14, 7:28*am, Paul Robinson
wrote:
Hi
Never activate if you don't have to

Worksheets("Effic").Range("B3:F18").Pictures.Inser t (Filename$)

will probably work if the code worked originally with the sheet on
top.
Not checked though.
regards
Paul

On May 14, 6:50*am, jad700 < wrote:

Dim Pict As Object
Dim p As Object
Filename$ = "C:\aScopePic\jdpic7.png"
DoThis$ = "c:\windows\wgetbin\wget.exe *-t1 -O"
DoThis$ = DoThis$ + "C:\aScopePic\jdpic8.png"
DoThis$ = DoThis$ + " 10.32.54.19/Image.png"
If Dir(Filename$) = "" Then Stop
ret = Shell(DoThis$):
' Works so far, pic saved locally
' Now the following works ONLY if the Effic tab was on top when I run
the VBA
' Otherwise the next line *returns " Select method of range class
failed"
Worksheets("Effic").Range("B3:F18").Select
Worksheets("Effic").Range("B3:F18").Activate
ActiveSheet.Pictures.Insert (Filename$)
' I would like to be able to insert the picture onto any of the
sheets
' THANK YOU !!!!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default " Select method of range class failed" if sheet not on top

Worksheets("Effic").Range("B3:F18").Pictures.Inser t (LocalPicFilename
$)
Did not work !
The error was ....
Error 438
Object does not support this property or method
.....
However this does work
Worksheets("Picts").Select
Worksheets("Picts").Range("M16").Select
ActiveSheet.Pictures.Insert (LocalPicFilename$)
Worksheets("AllData").Select

Is using Select b etter than using Activate ??
Please see questions in previous post.
Thanks again !!!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default " Select method of range class failed" if sheet not on top

Hi
Q1
Sheet("Effic").Cells(8, CurColSh4%).Value = "XYZ"

will work if CurColSh4% is a number.

Q2
Right click each button, go to Format Control and choose Properties.
Click on "Don't move or size with cells".

Q3
Don't know - very code dependent.

Q4
For a worksheet you can use

Set MyRange = Worksheets("ThisOne").Range("B1:C4")

or
With Worksheets("ThisOne").
Set MyRange = .Range(.Cells(1,2), .Cells(4,3))
End With

(note the dots in front of range and Cells). The second syntax is
useful if you generate cell locations with numerical variables.

On your other question, the macro recorder tends to generate code
which selects and activates as that is what your mouse does. You can
pretty much always avoid this in code and it gives you more control
over what you are doing (and makes it easier to read!). As a general
principle this example,

Worksheets("ThisOne").Activate
Range("A1").Select
Selection.Value = 3

which is what you might do with the mouse to put 3 in A1 on sheet
"ThisOne", can be replaced with

Worksheets("ThisOne").Range("A1").Value = 3

I don't know why
Worksheets("Picts").Range("F5").Activate
ActiveSheet.Pictures.Insert (Filename$)

works for you! I cannot see Pictures as a worksheet Property, Method
or function (introduced in Excel 2007 maybe?). As you don't refer to
the Range("F5") in the insert then it may be superfluous and this
might work (should work!),

Worksheets("Picts").Pictures.Insert (Filename$)

using the principle above.

regards
Paul


On May 14, 10:54*pm, jad700 wrote:
Many thanks Avi and Paul
I got that fixed last night, but now have several more questions.
----
Q1
I use lines like
Sheet4.Cells(8, CurColSh4%) = "XYZ" and
Sheet4.Cells.ClearContents
extensively through my code, but I am concerned that the order of the
worksheets might change and would be a disaster.
I think I would like to use
Sheet("Effic").Cells(8, CurColSh4%) = "XYZ" * * but do not know the
right syntax.
----
Q2
The buttons I have made move around when running, specifically one
moves on top of the other. How can I lock their location.
---
Q3 the file size just keeps getting bigger, currently 5 meg for a 1000
line program,
even if I clear contents of the sheets. How can I fix this ?
---
Q4 - How can I get the current Worksheet and location (Range) as
variables, so I can jump back to them.
---
Optional -
Why Never activate if you don't have to? What is the difference
between activate and select.?
---
By the way, *to fix it I used
' Store the pic on the Picts tab
Worksheets("Picts").Activate
Worksheets("Picts").Range("F5").Activate
ActiveSheet.Pictures.Insert (Filename$)
Worksheets("AllData").Activate
( Sorry Paul, I will go back and try your line of code )
-----
THANKS !!

On May 14, 7:28*am, Paul Robinson
wrote:



Hi
Never activate if you don't have to


Worksheets("Effic").Range("B3:F18").Pictures.Inser t (Filename$)


will probably work if the code worked originally with the sheet on
top.
Not checked though.
regards
Paul


On May 14, 6:50*am, jad700 < wrote:


Dim Pict As Object
Dim p As Object
Filename$ = "C:\aScopePic\jdpic7.png"
DoThis$ = "c:\windows\wgetbin\wget.exe *-t1 -O"
DoThis$ = DoThis$ + "C:\aScopePic\jdpic8.png"
DoThis$ = DoThis$ + " 10.32.54.19/Image.png"
If Dir(Filename$) = "" Then Stop
ret = Shell(DoThis$):
' Works so far, pic saved locally
' Now the following works ONLY if the Effic tab was on top when I run
the VBA
' Otherwise the next line *returns " Select method of range class
failed"
Worksheets("Effic").Range("B3:F18").Select
Worksheets("Effic").Range("B3:F18").Activate
ActiveSheet.Pictures.Insert (Filename$)
' I would like to be able to insert the picture onto any of the
sheets
' THANK YOU !!!!- Hide quoted text -


- Show quoted text -


Reply
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
"Select method of Range class failed" Error Ayo Excel Discussion (Misc queries) 3 September 2nd 08 07:58 PM
Run-time error "1004" Select method of range class failed Tallan Excel Discussion (Misc queries) 3 March 7th 07 05:22 PM
VBA error 1004 "Select method of Range class failed" Matt J Excel Programming 6 July 3rd 04 10:05 PM
Error 1004, "select method of range class failed" paritoshmehta[_11_] Excel Programming 3 May 6th 04 10:09 PM
Runtime Error "1004" Select Method of Range Class Failed Stephen[_7_] Excel Programming 4 April 10th 04 06:28 AM


All times are GMT +1. The time now is 06:57 PM.

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

About Us

"It's about Microsoft Excel"