#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro issue

I setup a Macro that opens up a bunch of text file and imports them int
a CSV file and then data I need is copy and pasted into specific cells


Now the problem is that everytime i run the Macro, i get over 31 ope
CSV files. Is there a way i can add something to the script that wil
close the file automatically for me, but leave my main XLS file open?

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Macro issue

Alex

presumably you are going around a loop to open and process the files? Why
not record a macro to close one of the CSV files and then incorporate this
code into your loop after you have processed the data ?

If you post an extract from your code (the loop to open and process the csv
files) I'm sure someone will draft some code for you.

Regards

Trevor


"alexm999 " wrote in message
...
I setup a Macro that opens up a bunch of text file and imports them into
a CSV file and then data I need is copy and pasted into specific cells.


Now the problem is that everytime i run the Macro, i get over 31 open
CSV files. Is there a way i can add something to the script that will
close the file automatically for me, but leave my main XLS file open??


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro issue

Alex,

Something like

Workbooks.Open Filename:="C:\myfile.txt"
' do your thing
Activeworkbook.Close

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"alexm999 " wrote in message
...
I setup a Macro that opens up a bunch of text file and imports them into
a CSV file and then data I need is copy and pasted into specific cells.


Now the problem is that everytime i run the Macro, i get over 31 open
CSV files. Is there a way i can add something to the script that will
close the file automatically for me, but leave my main XLS file open??


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro issue

Here's the code:

what can i add to get the file 2.txt to close at the end?

Sub macro1()
Workbooks.OpenText Filename:="E:\UDC\2.TXT", Origin:=xlWindows,
StartRow _
:=7, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False,
Comma:=False, _
Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1),
Array(2, 1), Array(3 _
, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1),
Array(8, 1))
Range("F13").Select
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
Range("C8").Select
ActiveSheet.Paste
Range("E8").Select
Windows("2.TXT").Activate
Range("F14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
ActiveSheet.Paste
Range("J8").Select
Windows("2.TXT").Activate
Range("E17").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
ActiveSheet.Paste
Range("K8").Select
Windows("2.TXT").Activate
Range("G18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
ActiveSheet.Paste
ActiveWindow.LargeScroll ToRight:=2
Range("AI8").Select
Windows("2.TXT").Activate
Range("F18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
ActiveSheet.Paste


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro issue

Alex,

Try this

Sub macro1()
Dim oThisFile As Workbook '<<<<<<<<<<<<<<<<<<<< New code
Workbooks.OpenText Filename:="E:\UDC\2.TXT", Origin:=xlWindows,
Set oThisFile As ActiveWorkbook '<<<<<<<<<<<<<<<<<<<< New code
StartRow _
:=7, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, Tab:=True, Semicolon:=False,
Comma:=False, _
Space:=True, Other:=False, FieldInfo:=Array(Array(1, 1),
Array(2, 1), Array(3 _
, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1),
Array(8, 1))
Range("F13").Select
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
Range("C8").Select
ActiveSheet.Paste
Range("E8").Select
Windows("2.TXT").Activate
Range("F14").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
ActiveSheet.Paste
Range("J8").Select
Windows("2.TXT").Activate
Range("E17").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
ActiveSheet.Paste
Range("K8").Select
Windows("2.TXT").Activate
Range("G18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
ActiveSheet.Paste
ActiveWindow.LargeScroll ToRight:=2
Range("AI8").Select
Windows("2.TXT").Activate
Range("F18").Select
Application.CutCopyMode = False
Selection.Copy
Windows("DAILY OPERATIONS_2004.xls").Activate
ActiveSheet.Paste

oThisFile.Close '<<<<<<<<<<<<<<<<<<<< New code

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"alexm999 " wrote in message
...
Here's the code:

what can i add to get the file 2.txt to close at the end?





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
Issue with a macro juancarlos Excel Discussion (Misc queries) 18 September 17th 09 09:41 PM
Macro issue 2 Farhad Excel Discussion (Misc queries) 6 December 21st 08 07:14 PM
Macro issue Farhad Excel Discussion (Misc queries) 5 December 21st 08 06:05 PM
Macro issue Sue Excel Discussion (Misc queries) 0 October 8th 08 08:05 PM
Macro Issue basanth New Users to Excel 3 September 10th 08 06:05 PM


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

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"