Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Run time error 9

filetoopen contains a fully qualified path and is not a legal argument to
the workbooks collections

as an example:
filetoopen: "C:\my documents\myfile.xls"

workbooks("myfile.xls") is what is required.


Here is one work around:

Public filetoopen as variant

sub open()
filetoopen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If filetoopen < False Then
MsgBox "Open " & filetoopen
End If


Workbooks.OpenText Filename:=filetoopen , Origin:= _
xlWindows, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, _
2), Array(17, 2), Array(30, 2), Array(39, 2))

' reset the value of filetoopen here
filetoOpen = ActiveWorkbook.Name

Call subroutine

End sub

Sub subroutine()

Windows(filetoopen).activete 'I get run time error here

end sub

--
Regards,
Tom Ogilvy


Nathaniel Tigere wrote in message
...
I am writing a macro using getopenfilename to open the
file I want. The procedure works and it opens the file I
want. But when I want to use the file I have opened in
another Sub by calling the sub routine I get get run
time error 9 (Subscript out of range) when I use
windows(filetoopen).Activate to activate the file I
opened in my subroutine

My program looks as follows


Public filetoopen as variant

sub open()
filetoopen = Application _
.GetOpenFilename("Text Files (*.txt), *.txt")
If filetoopen < False Then
MsgBox "Open " & filetoopen
End If


Workbooks.OpenText Filename:=filetoopen , Origin:= _
xlWindows, StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, _
2), Array(17, 2), Array(30, 2), Array(39, 2))

Call subroutine

End sub

Sub subroutine()

Windows(filetoopen).activete 'I get run time error here

end sub



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
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Receiving run-time error only part of the time [email protected] Excel Discussion (Misc queries) 0 August 11th 07 12:01 AM
run-time error '91'-Close Button error ASCO IS Help Excel Discussion (Misc queries) 1 May 8th 06 04:25 PM
Run time error 1004, General ODBC error [email protected] New Users to Excel 0 September 19th 05 01:41 AM


All times are GMT +1. The time now is 08:04 PM.

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

About Us

"It's about Microsoft Excel"