Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Event Code Error trying to insert a picture

I am trying to get a picture to insert and am following the suggestion below.
After pasting the code into the View Code window the following error
appears on the first Dim statement in the code. I get "Microsoft Visual
Basic Complie Error: Expected: End of Statement". What am I doing wrong?


Copy the code below, right click the sheet tab, select "View Code" and
paste the code into the window that appears. I've assumed that your pictures
are stored on a sheet named "Pictures" and that Jane Doe's picture is named
"Jane Doe", and that the cell you want to enter the name into is cell A2, so
that the picture appears in cell A1. HTH, Bernie MS Excel MVP Private Sub
Worksheet_Change(ByVal Target As Range) Dim myShape As Shape Dim SC As Range
Dim mySh As Worksheet If Target.Cells.Count 1 Then Exit Sub If
Target.Address < "$A$2" Then Exit Sub Application.EnableEvents = False
Application.ScreenUpdating = False Set mySht = ActiveSheet On Error Resume
Next For Each myShape In mySht.Shapes If myShape.Name Like "*Final" Then
myShape.Delete Next myShape Worksheets("Pictures").Select
ActiveSheet.Shapes(Target.Value).Select Selection.Copy mySht.Select
Target.Offset(-1, 0).Select ActiveSheet.Paste Selection.Name = "'" &
mySht.Name & "'!" & Selection.Name & "Final" Target.Select
Application.EnableEvents = True Application.ScreenUpdating = True End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Event Code Error trying to insert a picture

Hi pmnaughton

The formatting look a bit odd, so I rearanged it to de code below.
I had an error olso but corrected the code.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim myShape As Shape
Dim SC As Range
Dim mySht As Worksheet
If Target.Cells.Count 1 Then Exit Sub
If Target.Address < "$A$2" Then Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False
Set mySht = ActiveSheet
On Error Resume Next
For Each myShape In mySht.Shapes
If myShape.Name Like "*Final" Then myShape.Delete
Next myShape
Worksheets("Pictures").Select
ActiveSheet.Shapes(Target.Value).Select
Selection.Copy
mySht.Select
Target.Offset(-1, 0).Select
ActiveSheet.Paste
Selection.Name = "'" & mySht.Name & "'!" & Selection.Name &
"Final"
Target.Select
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

HTH,

Wouter
  #3   Report Post  
Posted to microsoft.public.excel.programming
GB GB is offline
external usenet poster
 
Posts: 230
Default Event Code Error trying to insert a picture

Not sure how literal you were about your copying and pasting, but and I'm not
trying to be a smart @$$ is the code broken up into it's logical parts and
lines?

Dim mySh as Worksheet

If Target.cells....

Application.EnableEvents = False

Application..... etc..?




"pmnaughton" wrote:

I am trying to get a picture to insert and am following the suggestion below.
After pasting the code into the View Code window the following error
appears on the first Dim statement in the code. I get "Microsoft Visual
Basic Complie Error: Expected: End of Statement". What am I doing wrong?


Copy the code below, right click the sheet tab, select "View Code" and
paste the code into the window that appears. I've assumed that your pictures
are stored on a sheet named "Pictures" and that Jane Doe's picture is named
"Jane Doe", and that the cell you want to enter the name into is cell A2, so
that the picture appears in cell A1. HTH, Bernie MS Excel MVP Private Sub
Worksheet_Change(ByVal Target As Range) Dim myShape As Shape Dim SC As Range
Dim mySh As Worksheet If Target.Cells.Count 1 Then Exit Sub If
Target.Address < "$A$2" Then Exit Sub Application.EnableEvents = False
Application.ScreenUpdating = False Set mySht = ActiveSheet On Error Resume
Next For Each myShape In mySht.Shapes If myShape.Name Like "*Final" Then
myShape.Delete Next myShape Worksheets("Pictures").Select
ActiveSheet.Shapes(Target.Value).Select Selection.Copy mySht.Select
Target.Offset(-1, 0).Select ActiveSheet.Paste Selection.Name = "'" &
mySht.Name & "'!" & Selection.Name & "Final" Target.Select
Application.EnableEvents = True Application.ScreenUpdating = True End Sub



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
Copy picture and remove event code [email protected] Excel Programming 1 March 19th 07 05:14 AM
insert a picture in to a comment but picture not save on hard disk Pablo Excel Discussion (Misc queries) 0 February 21st 07 03:48 PM
Insert Picture in Pivot Table with code VB ancasa Excel Programming 0 May 30th 05 04:11 PM
Insert VBA code with a macro in a .xls file by workbook open event mihai[_3_] Excel Programming 8 July 29th 04 01:49 PM
Code to Insert a picture using VC++ keepitcool Excel Programming 1 May 28th 04 03:01 PM


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

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"