View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Sam Sam is offline
external usenet poster
 
Posts: 699
Default ERROR: subscript out of range

Hey Dave, Thanks for the help.
I still get a Subscript out of range error if i use:
Set wbk = Workbooks("WorkBook1.xls")

But this works fine:
Set wbk = Workbooks.open("C:\Documents\WorkBook1.xls")

should it be this way?

Thanks in advance



"Dave Peterson" wrote:

To use this line:
Set wbk = Workbooks("C:\Documents\WorkBook1")
The workbook has to be open already.

And you don't include the drive or path.

This may fail:
Set wbk = Workbooks("WorkBook1")
This will always work:
Set wbk = Workbooks("WorkBook1.xls")



sam wrote:

Hi All, I am getting subscript out of range error on this line:

---------------Set wbk = Workbooks("C:\Documents\WorkBook1")

here is my code

Sub Submit_Click()

Dim wbk As Workbook
Dim ws As Worksheet
Dim FName As String

Set wbk = Workbooks("C:\Documents\WorkBook1")

With Worksheets("Sheet1")

Range("A1").Value = Me.Name.Value

End With

FName = "C:\Documents\" _
& "File_of" & "-" & Me.Name.Value & ".xls"

Application.DisplayAlerts = False
With wbk

.SaveAs Filename:=FName

.Close

End With

end sub

Thanks in advance


--

Dave Peterson