PC Review


Reply
Thread Tools Rate Thread

Code to work with ONLY active Sheet not all ?

 
 
Corey
Guest
Posts: n/a
 
      9th Oct 2006
The below code inserts a Photo into the selected cell and sizes it to suit
my needs,
But i need this code to ONLY place a photo into the active sheet instead of
ALL sheets in the workbook.
How can i modify the below to do this??


#######################################################################
Sub Picture_Adder()
Application.ScreenUpdating = False
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim myPic As Picture
Dim res As Variant
'Const sAddress As String = ActiveCell
Set WB = ActiveWorkbook
res = Application.GetOpenFilename _
("Image Files (*.jpg), *.jpg")
If res = False Then Exit Sub
For Each SH In WB.Worksheets ' <======================= ONLY ACTIVE
WORK SHEET NOT ALL WORKSHEETS
Set rng = ActiveCell 'SH.Range(sAddress)
Set myPic = SH.Pictures.Insert(res)
With myPic
.Top = rng.Top
.Left = rng.Left
myPic.ShapeRange.LockAspectRatio = msoFalse
myPic.ShapeRange.Height = 177#
myPic.ShapeRange.Width = 235.5
myPic.ShapeRange.Rotation = 0#
End With
Next SH ' <======================================= DELETE THIS
Application.ScreenUpdating = True
End Sub

################################################################################



Regards

Corey


 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      9th Oct 2006
Sub Picture_Adder()
Application.ScreenUpdating = False
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim myPic As Picture
Dim res As Variant
'Const sAddress As String = ActiveCell
Set WB = ActiveWorkbook
res = Application.GetOpenFilename _
("Image Files (*.jpg), *.jpg")
If res = False Then Exit Sub
set SH = Activesheet
Set rng = ActiveCell
Set myPic = SH.Pictures.Insert(res)
With myPic
.Top = rng.Top
.Left = rng.Left
myPic.ShapeRange.LockAspectRatio = msoFalse
myPic.ShapeRange.Height = 177#
myPic.ShapeRange.Width = 235.5
myPic.ShapeRange.Rotation = 0#
End With
End if
Application.ScreenUpdating = True
End Sub

--
Regards,
Tom Ogilvy


"Corey" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The below code inserts a Photo into the selected cell and sizes it to suit
> my needs,
> But i need this code to ONLY place a photo into the active sheet instead
> of ALL sheets in the workbook.
> How can i modify the below to do this??
>
>
> #######################################################################
> Sub Picture_Adder()
> Application.ScreenUpdating = False
> Dim WB As Workbook
> Dim SH As Worksheet
> Dim rng As Range
> Dim myPic As Picture
> Dim res As Variant
> 'Const sAddress As String = ActiveCell
> Set WB = ActiveWorkbook
> res = Application.GetOpenFilename _
> ("Image Files (*.jpg), *.jpg")
> If res = False Then Exit Sub
> For Each SH In WB.Worksheets ' <======================= ONLY ACTIVE
> WORK SHEET NOT ALL WORKSHEETS
> Set rng = ActiveCell 'SH.Range(sAddress)
> Set myPic = SH.Pictures.Insert(res)
> With myPic
> .Top = rng.Top
> .Left = rng.Left
> myPic.ShapeRange.LockAspectRatio = msoFalse
> myPic.ShapeRange.Height = 177#
> myPic.ShapeRange.Width = 235.5
> myPic.ShapeRange.Rotation = 0#
> End With
> Next SH ' <======================================= DELETE THIS
> Application.ScreenUpdating = True
> End Sub
>
> ################################################################################
>
>
>
> Regards
>
> Corey
>



 
Reply With Quote
 
Corey
Guest
Posts: n/a
 
      9th Oct 2006

Thanks Tom.


:-)




Regards

Corey


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need VBA Code to Let User Define Active Sheet =?Utf-8?B?enVsZmVyNw==?= Microsoft Excel Misc 3 29th Mar 2007 02:59 PM
Need help in setting active Excel work sheet in VB6. =?Utf-8?B?Q3JhaWdib2I=?= Microsoft Outlook VBA Programming 1 10th Oct 2006 06:40 AM
How do i copy a active sheet to a new sheet with code and everything Karill Microsoft Excel Programming 2 11th Apr 2006 06:22 PM
Code to make a sheet active =?Utf-8?B?aHNoYXloMHJu?= Microsoft Excel Programming 10 5th Feb 2006 10:28 PM
Changing code that set's print area...to active sheet only KimberlyC Microsoft Excel Programming 4 10th Jul 2005 10:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:29 AM.