Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run Time Error 9

Could anyone please explain why would I get a Run Time Error 9 with
this code?

Sub submit_roster()
Dim myName As String
Dim myFile As String
Dim myWeek As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False

myFile = ActiveWorkbook.Name
myName = ActiveSheet.Name
myDate = Range("C5").Value
myName = myName & ". " & myDate
If Range("C5").Value = "" Then
MsgBox ("Pick a week to submit from the dropdown list.")
Range("C5").Select
Else
Range("C10:C192").Select
ActiveSheet.Unprotect Password:="richmond"
Selection.locked = True
ActiveSheet.Protect Password:="richmond"
Range("C5").Select
myCheck = vbIgnore
myCheck = MsgBox("Your " & myDate & " roster is now saved.
Are you ready to finalize by sending it to the league?", vbYesNo)
If myCheck = vbYes Then

Workbooks.Add
Sheets(Array("Sheet2", "Sheet3")).Select
ActiveWindow.SelectedSheets.Delete
ActiveWorkbook.SaveAs myName & ".xls"

Windows(myFile).Activate
Cells.Copy
Windows(myName).Activate
ActiveSheet.Paste

ActiveSheet.Name = Range("C5").Value & " Roster
Submission"
Range("C5").Select
Selection.locked = True
ActiveSheet.Protect Password:="richmond"
ActiveWorkbook.Save

MsgBox ("The file '" & myName & "' has been created and
saved in " & ActiveWorkbook.Path & ". Please attach it in an email
and send it to the league distribution list.")
Else
MsgBox ("Your submission file was not created.")
Range("C5").Select
End If
End If

Application.ScreenUpdating = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Run Time Error 9

sure,
when you do

myName = myName & ". " & myDate

myname has a value like "abcd.xls"

whatever you append to it will be after the .xls

so myname will be like "abcd.xls.20040831"

you need to do

myName = left(myname,len(myname)-4) & mydate & ".xls"

then change
ActiveWorkbook.SaveAs myName & ".xls"
to
ActiveWorkbook.SaveAs myName

--
Regards,
Tom Ogilvy

"Bankonit9" wrote in message
om...
Could anyone please explain why would I get a Run Time Error 9 with
this code?

Sub submit_roster()
Dim myName As String
Dim myFile As String
Dim myWeek As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False

myFile = ActiveWorkbook.Name
myName = ActiveSheet.Name
myDate = Range("C5").Value
myName = myName & ". " & myDate
If Range("C5").Value = "" Then
MsgBox ("Pick a week to submit from the dropdown list.")
Range("C5").Select
Else
Range("C10:C192").Select
ActiveSheet.Unprotect Password:="richmond"
Selection.locked = True
ActiveSheet.Protect Password:="richmond"
Range("C5").Select
myCheck = vbIgnore
myCheck = MsgBox("Your " & myDate & " roster is now saved.
Are you ready to finalize by sending it to the league?", vbYesNo)
If myCheck = vbYes Then

Workbooks.Add
Sheets(Array("Sheet2", "Sheet3")).Select
ActiveWindow.SelectedSheets.Delete
ActiveWorkbook.SaveAs myName & ".xls"

Windows(myFile).Activate
Cells.Copy
Windows(myName).Activate
ActiveSheet.Paste

ActiveSheet.Name = Range("C5").Value & " Roster
Submission"
Range("C5").Select
Selection.locked = True
ActiveSheet.Protect Password:="richmond"
ActiveWorkbook.Save

MsgBox ("The file '" & myName & "' has been created and
saved in " & ActiveWorkbook.Path & ". Please attach it in an email
and send it to the league distribution list.")
Else
MsgBox ("Your submission file was not created.")
Range("C5").Select
End If
End If

Application.ScreenUpdating = True

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Run Time Error 9

Try this

Dim mydate As Long
Dim mycheck As Integer

Dave


"Bankonit9" wrote in message
om...
Could anyone please explain why would I get a Run Time Error 9 with
this code?

Sub submit_roster()
Dim myName As String
Dim myFile As String
Dim myWeek As String

Application.ScreenUpdating = False
Application.DisplayAlerts = False

myFile = ActiveWorkbook.Name
myName = ActiveSheet.Name
myDate = Range("C5").Value
myName = myName & ". " & myDate
If Range("C5").Value = "" Then
MsgBox ("Pick a week to submit from the dropdown list.")
Range("C5").Select
Else
Range("C10:C192").Select
ActiveSheet.Unprotect Password:="richmond"
Selection.locked = True
ActiveSheet.Protect Password:="richmond"
Range("C5").Select
myCheck = vbIgnore
myCheck = MsgBox("Your " & myDate & " roster is now saved.
Are you ready to finalize by sending it to the league?", vbYesNo)
If myCheck = vbYes Then

Workbooks.Add
Sheets(Array("Sheet2", "Sheet3")).Select
ActiveWindow.SelectedSheets.Delete
ActiveWorkbook.SaveAs myName & ".xls"

Windows(myFile).Activate
Cells.Copy
Windows(myName).Activate
ActiveSheet.Paste

ActiveSheet.Name = Range("C5").Value & " Roster
Submission"
Range("C5").Select
Selection.locked = True
ActiveSheet.Protect Password:="richmond"
ActiveWorkbook.Save

MsgBox ("The file '" & myName & "' has been created and
saved in " & ActiveWorkbook.Path & ". Please attach it in an email
and send it to the league distribution list.")
Else
MsgBox ("Your submission file was not created.")
Range("C5").Select
End If
End If

Application.ScreenUpdating = True

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Run Time Error 9

Thank you for your reply Tom.

One question.

If I set myName to the activesheet name, why would it end in .xls?

Wouldnt that only be the case if i set myName to the workbooks name, and
not the sheet?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Run Time Error 9

You are correct - it was the variable above that was being assigned to the
workbook name. Trying to scroll through your code in a small window,
looking for assignments that might raise such an error . . . well, led to an
incorrect conclusion. You haven't said what line is highlighted when you
get the error. When you get the error, query the value of the argument to
the collection and see if it matches anything. A subscript out of range
error is usually caused by a name, used as an index to a collection, which
doesn't match any members of the collection. Such as the workbooks
collection, worksheets collection and so forth. You should examine such
variables as myName and the others that you are using as arguments to index
to the collection.

--
Regards,
Tom Ogilvy

"Benjamin Kochanski" wrote in message
...
Thank you for your reply Tom.

One question.

If I set myName to the activesheet name, why would it end in .xls?

Wouldnt that only be the case if i set myName to the workbooks name, and
not the sheet?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Run Time Error 9

Thanks Dave.

I somehow forgot to Dim those guys...wouldnt I want to Dim myCheck as a
vbMsgBoxResult, rather than as an integer?



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM
Befuddled with For Next Loop ------ Run - Time Error '13' Type Mismatch Error rdavis7408 Excel Programming 1 August 25th 04 03:54 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM
Run-time error '11' & Run-time error '1004' Piers Clinton-Tarestad Excel Programming 0 January 9th 04 08:35 PM


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