Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default Macro doesn't insert image when spreadsheet is protected

Hello, my name is ATang. I have put in the below codes in an excel file in
order to allow the users to select a company name in a particular cell, then
the respective logo will automatically pop up in another cell. It works well
when the spreadsheet is NOT protected. If the spreadsheet is protected, the
logo stays the same and the logic doesn't work even I change the company
name. Have tried to unlock this cell which contains the logo, protect the
worksheet and change the company name again, the correct logo still doesn't
pop up. Is there a way to make this macro work by protecting the worksheet
at the same time? Appreciate your advice. Below captures the code details:

********************************************
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$6" Then
Application.EnableEvents = False
HandleBMP
Application.EnableEvents = True
End If
End Sub

Sub HandleBMP()
Dim myCell As Range
Set myCell = Selection

On Error Resume Next

If Range("G6").Value = "Vendor" Then
ActiveSheet.Shapes("B1 Picture").Delete
ActiveSheet.Shapes("A1 Picture").Delete
Range("A1").Select
ActiveSheet.Pictures.Insert( _
"P:\Merchandising\GSL Logo Picture.bmp").Select
Selection.Name = "A1 Picture"
Else

ActiveSheet.Shapes("A1 Picture").Delete
End If

If Range("G6").Value = "Customer" Then
ActiveSheet.Shapes("B1 Picture").Delete
ActiveSheet.Shapes("A1 Picture").Delete
Range("A1").Select
ActiveSheet.Pictures.Insert( _
"P:\Merchandising\Solito Logo Picture.bmp").Select
Selection.Name = "B1 Picture"
Else

ActiveSheet.Shapes("B1 Picture").Delete
End If

myCell.Select
End Sub
********************************************

Thank you very much,
ATang

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 341
Default Macro doesn't insert image when spreadsheet is protected

Hi ATang,

Your code seems good so I won't bother to correct anything in there.

If you didn't have that statement "On Error Resume Next" I believe you would
see an error coming up when the sheet is protected and you try to add and
delete the pictures. (Try it without that statement and you will see an
error text).

The tip that I think you really need to move forwards is this:

sheets("sheetname").protect password:="fish"
'some code here
sheets("sheetname").unprotect password:="fish"

Hope that helps! Please rate me. Thanks!
--
Allllen


"ATang" wrote:

Hello, my name is ATang. I have put in the below codes in an excel file in
order to allow the users to select a company name in a particular cell, then
the respective logo will automatically pop up in another cell. It works well
when the spreadsheet is NOT protected. If the spreadsheet is protected, the
logo stays the same and the logic doesn't work even I change the company
name. Have tried to unlock this cell which contains the logo, protect the
worksheet and change the company name again, the correct logo still doesn't
pop up. Is there a way to make this macro work by protecting the worksheet
at the same time? Appreciate your advice. Below captures the code details:

********************************************
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$6" Then
Application.EnableEvents = False
HandleBMP
Application.EnableEvents = True
End If
End Sub

Sub HandleBMP()
Dim myCell As Range
Set myCell = Selection

On Error Resume Next

If Range("G6").Value = "Vendor" Then
ActiveSheet.Shapes("B1 Picture").Delete
ActiveSheet.Shapes("A1 Picture").Delete
Range("A1").Select
ActiveSheet.Pictures.Insert( _
"P:\Merchandising\GSL Logo Picture.bmp").Select
Selection.Name = "A1 Picture"
Else

ActiveSheet.Shapes("A1 Picture").Delete
End If

If Range("G6").Value = "Customer" Then
ActiveSheet.Shapes("B1 Picture").Delete
ActiveSheet.Shapes("A1 Picture").Delete
Range("A1").Select
ActiveSheet.Pictures.Insert( _
"P:\Merchandising\Solito Logo Picture.bmp").Select
Selection.Name = "B1 Picture"
Else

ActiveSheet.Shapes("B1 Picture").Delete
End If

myCell.Select
End Sub
********************************************

Thank you very much,
ATang

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3
Default Macro doesn't insert image when spreadsheet is protected

Hi Allllen,
Thank you for your quick reply. Yes, you are right, by taking out the "On
Error Resume Next", I was prompted with error message when trying to protect
the file. But, I'm really not good at coding in Excel, to get around this
problem, can you kindly advise exactly how and where should I insert your
suggested 2 statements into the below paragraph in order to achieve the
mentioned mission???

sheets("sheetname").protect password:="fish"
'some code here
sheets("sheetname").unprotect password:="fish"

Really appreciate your help in advance!!!
Regards, ATang



"Allllen" wrote:

Hi ATang,

Your code seems good so I won't bother to correct anything in there.

If you didn't have that statement "On Error Resume Next" I believe you would
see an error coming up when the sheet is protected and you try to add and
delete the pictures. (Try it without that statement and you will see an
error text).

The tip that I think you really need to move forwards is this:

sheets("sheetname").protect password:="fish"
'some code here
sheets("sheetname").unprotect password:="fish"

Hope that helps! Please rate me. Thanks!
--
Allllen


"ATang" wrote:

Hello, my name is ATang. I have put in the below codes in an excel file in
order to allow the users to select a company name in a particular cell, then
the respective logo will automatically pop up in another cell. It works well
when the spreadsheet is NOT protected. If the spreadsheet is protected, the
logo stays the same and the logic doesn't work even I change the company
name. Have tried to unlock this cell which contains the logo, protect the
worksheet and change the company name again, the correct logo still doesn't
pop up. Is there a way to make this macro work by protecting the worksheet
at the same time? Appreciate your advice. Below captures the code details:

********************************************
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$G$6" Then
Application.EnableEvents = False
HandleBMP
Application.EnableEvents = True
End If
End Sub

Sub HandleBMP()
Dim myCell As Range
Set myCell = Selection

On Error Resume Next

If Range("G6").Value = "Vendor" Then
ActiveSheet.Shapes("B1 Picture").Delete
ActiveSheet.Shapes("A1 Picture").Delete
Range("A1").Select
ActiveSheet.Pictures.Insert( _
"P:\Merchandising\GSL Logo Picture.bmp").Select
Selection.Name = "A1 Picture"
Else

ActiveSheet.Shapes("A1 Picture").Delete
End If

If Range("G6").Value = "Customer" Then
ActiveSheet.Shapes("B1 Picture").Delete
ActiveSheet.Shapes("A1 Picture").Delete
Range("A1").Select
ActiveSheet.Pictures.Insert( _
"P:\Merchandising\Solito Logo Picture.bmp").Select
Selection.Name = "B1 Picture"
Else

ActiveSheet.Shapes("B1 Picture").Delete
End If

myCell.Select
End Sub
********************************************

Thank you very much,
ATang

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
how do I email amacro? leo Excel Worksheet Functions 24 August 9th 06 02:47 PM
Insert date in macro George Gee New Users to Excel 12 April 17th 06 05:44 AM
How do I insert an object onto a protected worksheet? Arthur.awg Excel Discussion (Misc queries) 0 March 21st 06 01:36 PM
Appending data from one spreadsheet to another using a macro DebP Excel Discussion (Misc queries) 3 December 1st 05 03:11 PM
How to see macro code of a password protected macro without a password? Dmitry Kopnichev Excel Worksheet Functions 5 October 27th 05 09:57 AM


All times are GMT +1. The time now is 11:11 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"