ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error while moving sheet (https://www.excelbanter.com/excel-programming/371487-error-while-moving-sheet.html)

Hello

Error while moving sheet
 
Hello;
I'm getting Run-time error '9': Subscript out of range
with this code on line with *.
Dim FName As String
FName = BP & "-" & EP & ".xls"
Path = "C:\TS\"
If Not FileExists(FName) Then
ActiveWorkbook.SaveAs FileName:=Path & FName, _
FileFormat:=xlNormal, Password:="++++", WriteResPassword:="++++"
ActiveWorkbook.Close
Else
Workbooks.Open FileName:=Path & FName, Password:="++++",
WriteResPassword:="++++"
ActiveWindow.ActivateNext

* Sheets(1).Move After:=Workbooks(" & FName & ").Sheets(Sheets.Count)

ActiveWorkbook.Close (True)
End If

When I enter actual file name it is fine.
PLease help,
Irek



stevebriz

Error while moving sheet
 

Irek
where do you have BP and EP dim'd and there strings set?
i am thinking the BP and EP strings are not passing to this module


Hello

Error while moving sheet
 
This is not the whole sub, and BP and EP do recalculate correctly
in Immediate window I see
? FName
Aug,01-Aug,15.xls

"stevebriz" wrote in message
ups.com...

Irek
where do you have BP and EP dim'd and there strings set?
i am thinking the BP and EP strings are not passing to this module




stevebriz

Error while moving sheet
 

Hello wrote:
This is not the whole sub, and BP and EP do recalculate correctly
in Immediate window I see
? FName
Aug,01-Aug,15.xls

"stevebriz" wrote in message
ups.com...

Irek
where do you have BP and EP dim'd and there strings set?
i am thinking the BP and EP strings are not passing to this module

if you remove the ".xls" from Fname does it open ok?


Hello

Error while moving sheet
 

"stevebriz" wrote in message
oups.com...

Hello wrote:
This is not the whole sub, and BP and EP do recalculate correctly
in Immediate window I see
? FName
Aug,01-Aug,15.xls

"stevebriz" wrote in message
ups.com...

Irek
where do you have BP and EP dim'd and there strings set?
i am thinking the BP and EP strings are not passing to this module

if you remove the ".xls" from Fname does it open ok?


Thx Steve
This is from the macro recorder:
Sheets("Jolanta").Move After:=Workbooks("Aug,01-Aug,15.xls").Sheets(1)

so .xls should be fine. Need to dig up dipper.
Irek



stevebriz

Error while moving sheet
 


try this
Sheets(1).Move After:=Workbooks(FName).Sheets(Sheets.Count)



All times are GMT +1. The time now is 02:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com