Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Visual Basic Error Run Time Error, Type Mismatch | Excel Discussion (Misc queries) | |||
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 | Excel Discussion (Misc queries) | |||
Receiving run-time error only part of the time | Excel Discussion (Misc queries) | |||
run-time error '91'-Close Button error | Excel Discussion (Misc queries) | |||
Run time error 1004, General ODBC error | New Users to Excel |