Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default SaveAs produces subscript error

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default SaveAs produces subscript error

Which line produces the error? Maybe the value in cell D39 is invalid.

Matthew Pfluger

"Andyjim" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default SaveAs produces subscript error


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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default SaveAs produces subscript error

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





"Andyjim" wrote:

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

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
Refresh produces #N/A error RhysPieces Links and Linking in Excel 1 July 11th 07 07:42 PM
Refresh produces #N?A error RhysPieces Excel Discussion (Misc queries) 1 July 10th 07 09:16 AM
CreateObject produces error Robert Chapman Excel Programming 0 August 15th 03 03:48 PM
SaveAs "subscript out of range" error (COM - SOAP) Matthia Excel Programming 0 July 11th 03 07:01 AM
SaveAs "subscript out of range" error (COM - SOAP) jaf Excel Programming 0 July 10th 03 07:59 PM


All times are GMT +1. The time now is 11:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"