Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default opening a file with wildcard

Hi,

The following script enables me to open a file and bring specific data into
a different workbork.

Problem : Once the data is in, I ask to go back to the initial file
"abc_SCCS_1*.csv" in order to close it but I get a Run-Error 9 : Script out
of range message.

What am I doing wrong? Tried variations of script but end up with different
error messages.

Many thanks in advance for any assistance.

Sub Openfile()
Dim i As Integer
With Application.FileSearch
.LookIn = "D:\path name"
'* represents wildcard characters
.Filename = "abc_SCCS_1*.csv"
If .Execute 0 Then 'Workbook exists
For i = 1 To .FoundFiles.Count
Workbooks.Open (.FoundFiles(i))
Next i
End If
End With
Columns("E:N").Select
Selection.Delete Shift:=xlToLeft
Range("D1:N1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("Macro_Extract data.xls").Activate
Sheets("abc_SCCS").Select
Range("A9").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Windows("abc_SCCS_1*.csv").Activate
ActiveWindow.Close


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default opening a file with wildcard

I actually found a work around ...

removed the last two lines with this
Application.Windows(2).Close

thanks!


"Dode" wrote:

Hi,

The following script enables me to open a file and bring specific data into
a different workbork.

Problem : Once the data is in, I ask to go back to the initial file
"abc_SCCS_1*.csv" in order to close it but I get a Run-Error 9 : Script out
of range message.

What am I doing wrong? Tried variations of script but end up with different
error messages.

Many thanks in advance for any assistance.

Sub Openfile()
Dim i As Integer
With Application.FileSearch
.LookIn = "D:\path name"
'* represents wildcard characters
.Filename = "abc_SCCS_1*.csv"
If .Execute 0 Then 'Workbook exists
For i = 1 To .FoundFiles.Count
Workbooks.Open (.FoundFiles(i))
Next i
End If
End With
Columns("E:N").Select
Selection.Delete Shift:=xlToLeft
Range("D1:N1").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("Macro_Extract data.xls").Activate
Sheets("abc_SCCS").Select
Range("A9").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Windows("abc_SCCS_1*.csv").Activate
ActiveWindow.Close


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
Opening file in Excel 2003 opens multipule instances of same file Ed_B Excel Discussion (Misc queries) 1 June 21st 07 07:10 PM
File:1 and File:2 -- Double Files when Opening One File dallin Excel Discussion (Misc queries) 1 January 25th 07 02:53 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
"Unable to read file" error message when opening a Excel file that contains a PivotTable report. Tim Marsden Charts and Charting in Excel 2 October 15th 05 02:10 PM
How to use the exact format in a csv file when opening a csv file tong Excel Discussion (Misc queries) 1 October 13th 05 05:41 AM


All times are GMT +1. The time now is 06:16 AM.

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"