Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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.Path
imagen = 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Runtime error 91: Object variable or With block variable not set

Try...

Private Sub ComboBox1_Change()

Dim fso As Object, rngFound As Range
Dim ruta$, imagen$, ruta_e_imagen$ 'type=String

Set fso = CreateObject("Scripting.FileSystemObject")
ruta = ActiveWorkbook.Path
imagen = ComboBox1.List(ComboBox1.ListIndex) & ".jpg"
ruta_e_imagen = ruta & "\FOTOS\" & imagen

If fso.FileExists(ruta_e_imagen) Then
Image1.Picture = LoadPicture(ruta_e_imagen)
Set rngFound = Cells.Find(What:=Replace(imagen, ".jpg", ""))
If rngFound Is Nothing Then GoTo NotFound

With rngFound
Label3 = .Offset(0, 1): Label2 = .Offset(0, 2)
Label12 = .Offset(0, 10): Label13 = .Offset(0, 11)
Label14 = .Offset(0, 12): Label15 = .Offset(0, 13)
Label16 = .Offset(0, 14)
End With 'rngFound
Else
GoTo NotFound
End If

NormalExit:
Exit Sub

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

--
Garry

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



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Runtime error 91: Object variable or With block variable not set

GS wrote:

This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com


Hey Garry, do me a favor. Kill that line, if possible.

--
I've come to realize tonight, my friend, the end of time is not so far away.
We cannot pray to save our lives.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Runtime error 91: Object variable or With block variable not set

GS wrote:

This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com


Hey Garry, do me a favor. Kill that line, if possible.


Uh.., that was anoying me but didn't think anyone would care. I think
it's gone now! Thanks for the nudge! ;-)

--
Garry

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Runtime error 91: Object variable or With block variable not set

GS wrote:

GS wrote:

This email is free from viruses and malware because avast! Antivirus
protection is active.
http://www.avast.com


Hey Garry, do me a favor. Kill that line, if possible.


Uh.., that was anoying me but didn't think anyone would care. I think
it's gone now! Thanks for the nudge! ;-)


Np. It was just a minor thing, really.

--
Your face just broke the language barrier.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Runtime error 91: Object variable or With block variable not set

My macro doesn't work if sheet is protected but it works if not protected what can i do?
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Runtime error 91: Object variable or With block variable not set

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


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Runtime error 91: Object variable or With block variable not set

Sorry.., wrong thread!

--
Garry

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


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Runtime error 91: Object variable or With block variable not set

I think something is wrong in my code to protect and no to protect:

Code:


Sub protegida () (TO PROTECT)
Application.ScreenUpdating = False

pw = "protegida"
Hoja1.Select

For i = 1 To Sheets.Count
Sheets(i).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=treu, AllowFiltering:=True, AllowUsingPivotTables:=True
Next i

Dim wsSheet As Worksheet
For Each wsSheet In ActiveWorkbook.Worksheets
If wsSheet.Name < Hoja1.Name Then
wsSheet.Visible = xlSheetVeryHidden
End If
Next wsSheet



End Sub

Sub edicion()(NOT TO PROTECT)

Application.ScreenUpdating = False
Hoja1.Select

For i = 1 To Sheets.Count
Sheets(i).Protect DrawingObjects:=False, Contents:=False, Scenarios:=False _
, AllowSorting:=False, AllowFiltering:=False, AllowUsingPivotTables:=False
Next i



Dim wsSheet As Worksheet

For Each wsSheet In ActiveWorkbook.Worksheets
If wsSheet.Name < Hoja1.Name Then
wsSheet.Visible = xlSheetVisible
End If

Next wsSheet

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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Runtime Error 91 Object variable or With block variable not set. Tim Excel Programming 9 June 5th 08 10:03 PM
Error Number: 91 object variable or With block Variable not set Hifni Excel Programming 1 January 9th 08 11:56 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


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