Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default My macro doesn't work if sheet is protected but it works if not protected

Runtime error 91: Object variable or With block variable not set

My code is


Private Sub ComboBox1_Change()

Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

ruta = ActiveWorkbook.Pathimagen = ComboBox1.List(ComboBox1.ListIndex) & ".jpg"

ruta_e_imagen = ruta & "\FOTOS\" & imagen
If fso.FileExists(ruta_e_imagen) Then

Image1.Picture = LoadPicture(ruta_e_imagen)


Cells.Find(What:=Replace(imagen, ".jpg", "")).Select <<----((ERROR HERE)
Label3 = ActiveCell.Offset(0, 1)
Label2 = ActiveCell.Offset(0, 2)
Label12 = ActiveCell.Offset(0, 10)
Label13 = ActiveCell.Offset(0, 11)
Label14 = ActiveCell.Offset(0, 12)
Label15 = ActiveCell.Offset(0, 13)
Label16 = ActiveCell.Offset(0, 14)

Else

MsgBox "La Imagen: " & imagen & ", NO está disponible"

End If

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default My macro doesn't work if sheet is protected but it works if not protected

I tried your code but the error is now he


Set c = Cells.Find(What:=Replace(imagen, ".jpg", ""))

Label3 = c.Offset(0, 1) <<<--- ERROR HERE
Label2 = c.Offset(0, 2)
Label12 = c.Offset(0, 10)
Label13 = c.Offset(0, 11)
Label14 = c.Offset(0, 12)
Label15 = c.Offset(0, 13)
Label16 = c.Offset(0, 14)
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default My macro doesn't work if sheet is protected but it works if not protected

From a previous post...

There's no reason to toggle protection when you reset protection when
the file is first opened. Make sure you set 'UserInterfaceOnly:=True'
so your code can modify the sheet but the user can't via the UI. Make
sure your code includes 'AllowFiltering:=True' OR set
'worksheet.EnableAutoFilter:=True'...

Dim wks As Variant
For Each wks In ActiveWorkbook.Worksheets
wks.Unprotect <password
wks.Protect Password:=<password, UserInterfaceOnly:=True, _
AllowFiltering:=True '//add more as req'd
Next 'wks

It's feasible, however, that not all sheets need/are protected in a
file so you may want to use a string constant of delimited sheetnames
that protection is applied to...

Const sSheetsToProtect$ = "Sheet1,Sheet2,Sheet4"
Dim vName As Variant
For Each wks In Split(sSheetsToProtect$, ",")
Sheets(vName).Unprotect <password
Sheets(vName).Protect Password:=<password, _
UserInterfaceOnly:=True, _
AllowFiltering:=True '//add more as req'd
Next 'wks

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


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
UDF doesn't work on a protected sheet in Excel 2003 CarpeDiem Excel Discussion (Misc queries) 0 February 10th 09 08:13 PM
UDF doesn't work on a protected sheet in Excel 2003 CarpeDiem Excel Discussion (Misc queries) 0 February 10th 09 08:13 PM
Find doesn't work if the sheet is protected ON Excel Discussion (Misc queries) 1 June 12th 08 03:49 PM
Macro doesn't work when sheet protected excel-chump[_2_] Excel Programming 2 September 21st 07 01:38 PM
Macro doesn't work on UserInterfaceOnly-protected sheet Kasama Excel Programming 8 August 8th 06 10:17 AM


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