Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

What is the Cause of this Error Q

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sean - 23 Sep 2007 12:46 GMT
I am hitting debug 1004

"Unable to get th SpecialCells property of the Range class"

Any suggestions on what is causing this and how do I amend?

Thanks
OssieMac - 23 Sep 2007 13:26 GMT
Hi Sean,

Need more info. Can you post your code please?

Regards,

OssieMac

> I am hitting debug 1004
>
[quoted text clipped - 3 lines]
>
> Thanks
Dave Peterson - 23 Sep 2007 13:34 GMT
Is your worksheet protected?

> I am hitting debug 1004
>
[quoted text clipped - 3 lines]
>
> Thanks

Signature

Dave Peterson

Sean - 23 Sep 2007 14:02 GMT
> Is your worksheet protected?
>
[quoted text clipped - 9 lines]
>
> Dave Peterson

Code is pretty long, but see below, the problem area is in

   .Range("AI3:AI4").Cells.SpecialCells(xlCellTypeConstants)
       If cell.Value Like "?*@?*.?*" Then
           strto = strto & cell.Value & ";"

This is where is obtains an e-mail address (which on my sheet are
valid). It has worked fine in the past but now its suddenly thrown up
this error

Sub Mail_New_Version()
   Dim FileExtStr As String
   Dim FileFormatNum As Long
   Dim Sourcewb As Workbook
   Dim Destwb As Workbook
   Dim TempFilePath As String
   Dim TempFileName As String
   Dim OutApp As Object
   Dim OutMail As Object
   Dim sh As Worksheet

   With Application
       .ScreenUpdating = False
       .EnableEvents = False
   End With

   Set Sourcewb = ActiveWorkbook

   Sheets("E-Figures").Visible = True
   Sheets("E-Access").Visible = True

   Sheets("E-Figures").Select
   ActiveSheet.Unprotect Password:="123"

   'Copy the sheets to a new workbook
   Sourcewb.Sheets(Array("E-Figures", "E-Access", "Rules")).Copy
   Set Destwb = ActiveWorkbook

   'Determine the Excel version and file extension/format
   With Destwb
       If Val(Application.Version) < 12 Then
           'You use Excel 97-2003
           FileExtStr = ".xls": FileFormatNum = -4143
       Else
           'You use Excel 2007
           'We exit the sub when your answer is NO in the security
dialog that you only
           'see  when you copy a sheet from a xlsm file with macro's
disabled.
           If Sourcewb.Name = .Name Then
               With Application
                   .ScreenUpdating = True
                   .EnableEvents = True
               End With
               MsgBox "Your answer is NO in the security dialog"
               Exit Sub
           Else
               Select Case Sourcewb.FileFormat
               Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
               Case 52:
                   If .HasVBProject Then
                       FileExtStr = ".xlsm": FileFormatNum = 52
                   Else
                       FileExtStr = ".xlsx": FileFormatNum = 51
                   End If
               Case 56: FileExtStr = ".xls": FileFormatNum = 56
               Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
               End Select
           End If
       End If
   End With

   '    'Change all cells in the worksheets to values if you want
   '    For Each sh In Destwb.Worksheets
   '        sh.Select
   '        With sh.UsedRange
   '            .Cells.Copy
   '            .Cells.PasteSpecial xlPasteValues
   '            .Cells(1).Select
   '        End With
   '        Application.CutCopyMode = False
   '        Destwb.Worksheets(1).Select
   '    Next sh

   'Save the new workbook/Mail it/Delete it
   TempFilePath = Environ$("temp") & "\"
   TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-
mmm-yy hh-mm")

   ActiveWindow.TabRatio = 0.908

   Set OutApp = CreateObject("Outlook.Application")
   OutApp.Session.Logon
   Set OutMail = OutApp.CreateItem(0)

   Sheets("E-Figures").Activate
   Range("A1").Select

   For Each cell In ThisWorkbook.Sheets("E-
Figures").Range("BJ1:BJ18")
   strbody = strbody & cell.Value & vbNewLine
   Next

   For Each cell In ThisWorkbook.Sheets("E-Figures") _
   .Range("AI3:AI4").Cells.SpecialCells(xlCellTypeConstants)
       If cell.Value Like "?*@?*.?*" Then
           strto = strto & cell.Value & ";"
       End If
   Next
   strto = Left(strto, Len(strto) - 1)
Dave Peterson - 23 Sep 2007 14:08 GMT
> > Is your worksheet protected?

<<snipped>>
Sean - 23 Sep 2007 14:30 GMT
> > > Is your worksheet protected?
>
> <<snipped>>

Dave it is but I unprotect it towards the start of the code

   Sheets("E-Figures").Select
   ActiveSheet.Unprotect Password:="123"

E-Figures is where the e-mail address in A13:AI4 reside, where I'm
having the problem
Dave Peterson - 23 Sep 2007 16:49 GMT
If there are no constants in that range, then this will fail...

   For Each cell In ThisWorkbook.Sheets("E-Figures") _
   .Range("AI3:AI4").Cells.SpecialCells(xlCellTypeConstants)

Maybe you could check first

dim RngToCheck as range
...

set rngtocheck = nothing
on error resume next
 set rngtocheck = ThisWorkbook.Sheets("E-Figures") _
     .Range("AI3:AI4").Cells.SpecialCells(xlCellTypeConstants)
on error goto 0

if rngtocheck is nothing then
  'what should happen
else
 For Each cell In rngtocheck.cells
     ...

> > > > Is your worksheet protected?
> >
[quoted text clipped - 7 lines]
> E-Figures is where the e-mail address in A13:AI4 reside, where I'm
> having the problem

Signature

Dave Peterson

Sean - 23 Sep 2007 17:02 GMT
> If there are no constants in that range, then this will fail...
>
[quoted text clipped - 35 lines]
>
> - Show quoted text -

Dave, not entirely sure what you mean. The contents of the cells
AI3:AI4 are

'joe.bloggs@abc.com
'jack.bloggs@abc.com

but it still fails.

BTW it worked previously with no problems, but in doesn't any more
Dave Peterson - 23 Sep 2007 18:55 GMT
I'm saying that if that range AI3:AI4 contains formulas or is empty, then that
code will fail.  It's looking for constants.  If there are no constants, then it
won't work.

Maybe you should double check that range once more.

> > If there are no constants in that range, then this will fail...
> >
[quoted text clipped - 45 lines]
>
> BTW it worked previously with no problems, but in doesn't any more

Signature

Dave Peterson

Sean - 23 Sep 2007 19:33 GMT
> I'm saying that if that range AI3:AI4 contains formulas or is empty, then that
> code will fail.  It's looking for constants.  If there are no constants, then it
[quoted text clipped - 57 lines]
>
> - Show quoted text -

Definitely Dave, there are values in AI3:AI4 in sheet E-Figures
Dave Peterson - 23 Sep 2007 23:12 GMT
Maybe you're unprotecting the wrong sheet:

Replace:
   Sheets("E-Figures").Select
   ActiveSheet.Unprotect Password:="123"

With

   Sheets("E-Figures").Unprotect Password:="123"

or even

   thisworkbook.Sheets("E-Figures").Unprotect Password:="123"

======
The only time I've seen .specialcells fail is when the sheet is protected or
there are no constants in that range.

I still think it's your data--not the code.

> > - Show quoted text -
>
> Definitely Dave, there are values in AI3:AI4 in sheet E-Figures

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.