Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Subscript out of range?

As a temporary fix to my larger problem so I can at least get the macro
in the system, I have put together this code. My problem is, I am
getting a Runtime Error 9: Subscript Out of Range on the
Windows(UF).Activate portion. Shouldn't I be able to reference a
variable I have defined earlier in a function like this? Also, am I
asking for trouble with the Kill function set up like it is?

Dim UF As Variant
Dim UFOld As Variant

UF = Application.GetOpenFilename(FileFilter:="XML Files
(*.xml)", Title:="This Weeks Projections for Marc")
Workbooks.Open Filename:=UF

Sheets("Marc").Select
Sheets("Marc").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Summary")
Windows(UF).Activate
ActiveWindow.Close

UFOld = Application.GetOpenFilename(FileFilter:="XML Files
(*.xml)", Title:="Last Weeks Projections for Marc")
Workbooks.Open Filename:=UFOld

Sheets("Marc").Select
Sheets("Marc").Name = "Marc Last Week"
Sheets("Marc Last Week").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Marc")
Windows(UFOld).Activate
ActiveWindow.Close
Kill (UFOld)


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Subscript out of range?

Jason,

The problem is that UF contains the complete pathname of the file
(e.g., "C:\Test\File.xls") and to access the Windows collection,
you need only the file name, without any path. You can split out
the path and get only the file name with code like

Dim UF As String
Dim FName As String
FName = Mid(UF, InStrRev(UF, "\") + 1)
Workbooks(FName).Activate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Jason Hancock" wrote in message
...
As a temporary fix to my larger problem so I can at least get

the macro
in the system, I have put together this code. My problem is, I

am
getting a Runtime Error 9: Subscript Out of Range on the
Windows(UF).Activate portion. Shouldn't I be able to reference

a
variable I have defined earlier in a function like this? Also,

am I
asking for trouble with the Kill function set up like it is?

Dim UF As Variant
Dim UFOld As Variant

UF = Application.GetOpenFilename(FileFilter:="XML Files
(*.xml)", Title:="This Weeks Projections for Marc")
Workbooks.Open Filename:=UF

Sheets("Marc").Select
Sheets("Marc").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Summary")
Windows(UF).Activate
ActiveWindow.Close

UFOld = Application.GetOpenFilename(FileFilter:="XML

Files
(*.xml)", Title:="Last Weeks Projections for Marc")
Workbooks.Open Filename:=UFOld

Sheets("Marc").Select
Sheets("Marc").Name = "Marc Last Week"
Sheets("Marc Last Week").Copy

After:=Workbooks("Projection
Summary.xls").Sheets("Marc")
Windows(UFOld).Activate
ActiveWindow.Close
Kill (UFOld)


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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Subscript out of range?

Workbooks(FName).Activate

might as well be
Windows(FName).Activate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Chip Pearson" wrote in message
...
Jason,

The problem is that UF contains the complete pathname of the

file
(e.g., "C:\Test\File.xls") and to access the Windows

collection,
you need only the file name, without any path. You can split

out
the path and get only the file name with code like

Dim UF As String
Dim FName As String
FName = Mid(UF, InStrRev(UF, "\") + 1)
Workbooks(FName).Activate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Jason Hancock" wrote in message
...
As a temporary fix to my larger problem so I can at least get

the macro
in the system, I have put together this code. My problem is,

I
am
getting a Runtime Error 9: Subscript Out of Range on the
Windows(UF).Activate portion. Shouldn't I be able to

reference
a
variable I have defined earlier in a function like this?

Also,
am I
asking for trouble with the Kill function set up like it is?

Dim UF As Variant
Dim UFOld As Variant

UF = Application.GetOpenFilename(FileFilter:="XML

Files
(*.xml)", Title:="This Weeks Projections for Marc")
Workbooks.Open Filename:=UF

Sheets("Marc").Select
Sheets("Marc").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Summary")
Windows(UF).Activate
ActiveWindow.Close

UFOld = Application.GetOpenFilename(FileFilter:="XML

Files
(*.xml)", Title:="Last Weeks Projections for Marc")
Workbooks.Open Filename:=UFOld

Sheets("Marc").Select
Sheets("Marc").Name = "Marc Last Week"
Sheets("Marc Last Week").Copy

After:=Workbooks("Projection
Summary.xls").Sheets("Marc")
Windows(UFOld).Activate
ActiveWindow.Close
Kill (UFOld)


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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Subscript out of range?

Jason

You need just the file name in the Windows( ).Activate. You've got the full
path.

try it like this:

Set wbUF = Workbooks.Open(Filename:=UF)
UFFN = wbUF.Name

Sheets("Marc").Select
Sheets("Marc").Copy _
After:=Workbooks("Projection Summary.xls").Sheets("Summary")
Windows(UFFN).Activate
ActiveWindow.Close

Regards

Trevor


"Jason Hancock" wrote in message
...
As a temporary fix to my larger problem so I can at least get the macro
in the system, I have put together this code. My problem is, I am
getting a Runtime Error 9: Subscript Out of Range on the
Windows(UF).Activate portion. Shouldn't I be able to reference a
variable I have defined earlier in a function like this? Also, am I
asking for trouble with the Kill function set up like it is?

Dim UF As Variant
Dim UFOld As Variant

UF = Application.GetOpenFilename(FileFilter:="XML Files
(*.xml)", Title:="This Weeks Projections for Marc")
Workbooks.Open Filename:=UF

Sheets("Marc").Select
Sheets("Marc").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Summary")
Windows(UF).Activate
ActiveWindow.Close

UFOld = Application.GetOpenFilename(FileFilter:="XML Files
(*.xml)", Title:="Last Weeks Projections for Marc")
Workbooks.Open Filename:=UFOld

Sheets("Marc").Select
Sheets("Marc").Name = "Marc Last Week"
Sheets("Marc Last Week").Copy After:=Workbooks("Projection
Summary.xls").Sheets("Marc")
Windows(UFOld).Activate
ActiveWindow.Close
Kill (UFOld)


*** 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
Subscript out of Range Steve Excel Discussion (Misc queries) 3 April 15th 09 04:01 PM
what does 'Subscript Out of range' mean?? Gary Excel Worksheet Functions 2 March 22nd 07 01:33 AM
9: Subscript out of range jenz21985 Excel Discussion (Misc queries) 6 May 5th 06 03:36 PM
SubScript Out Of Range. Sam Excel Programming 4 December 21st 03 02:10 AM
Subscript Out of Range John Wilson Excel Programming 2 September 7th 03 04:07 AM


All times are GMT +1. The time now is 12:11 PM.

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"