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 / January 2008

Tip: Looking for answers? Try searching our database.

SaveAs produces subscript error

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andyjim - 24 Jan 2008 18:02 GMT
I am trying to saving a file based on the text name in a designated cell in
the workbook.  However, with this code, I get an “subscript out of range”
error.   Do you know what I am doing wrong?

Thanks for your help.

Windows("fxRM_Update.xls").Activate  

Dim bk As Workbook, bk1 As Workbook
Dim sstr As String
Set bk = Workbooks("fxRM_update.xls")
sstr = bk.Worksheets("lookup").Range("d39").Value
Set bk1 = Workbooks(sstr)

ActiveWorkbook.SaveCopyAs filename:=Workbooks(bk1)

Andy
Matthew Pfluger - 24 Jan 2008 18:17 GMT
Which line produces the error?  Maybe the value in cell D39 is invalid.

Matthew Pfluger

> I am trying to saving a file based on the text name in a designated cell in
> the workbook.  However, with this code, I get an “subscript out of range”
[quoted text clipped - 13 lines]
>
> Andy
Andyjim - 24 Jan 2008 18:50 GMT
Hi Matthew-

Actually, I have a similar macro that works (see below).  And actually, I
don't think the saveas code is the problem.  It seems to error on the line:

Set bk1 = Workbooks(sstr)

Here is the similar macro that works:

Sub update4() 'defines user file in fxRM_Update.xls Need to insert this
everytime you reactivate fxRM_Update and want to refer back to user file.

Dim bk As Workbook, bk1 As Workbook
Dim sstr As String

 Set bk = Workbooks("fxRM_update.xls")

 sstr = bk.Worksheets("lookup").Range("d39").Value

 Set bk1 = Workbooks(sstr)

bk1.Activate

End Sub

Thanks for your help
JLGWhiz - 24 Jan 2008 21:54 GMT
It could be the file extension that is causing the problem, if the value in
d39 does not have one.

Try:  

Set bk1 = Workbooks(sstr & ".xls")  'modify for xl2007
ActiveWorkbook.SaveCopyAs filename:=bk1

> I am trying to saving a file based on the text name in a designated cell in
> the workbook.  However, with this code, I get an “subscript out of range”
[quoted text clipped - 13 lines]
>
> Andy
 
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.