ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro for moving sheets (https://www.excelbanter.com/excel-discussion-misc-queries/1005-macro-moving-sheets.html)

minhao

Macro for moving sheets
 
Hi
I have tons of data files in ASCII format.
I want to move all individual files as sheets in one excel file.
Is there anyway to program a macro to do this?


Dave O

It can be done, and the best way to get started is to record the macro
to perform the operation once, then alter the macro to accommodate the
rest of the files. Additionally, you may need to have 2 files open at
once: the "master" file that holds the imported text files, and a
"temporary" file that imports the text file. The macro may need to
switch from one file to the other to move the imported tab from the
temporary file to the master, and then close the temporary file.
You can post your code to this newsgroup for debugging assistance.


minhao

Hi Dave
Thanks for your reply
I have recorded the macro to move a sheet from the txt file to a root file.

How do I program it to move all the txt files to the root file?
I have named the file in such a way that the last two digits are in a
running series.
For example 04120801, 04120802,....04120899

Minhao


Sub Movesheet()
'
' Movesheet Macro
'

'
Sheets("04120802").Select
Sheets("04120802").Move Befo=Workbooks("root.xls").Sheets(1)
End Sub


"Dave O" wrote:

It can be done, and the best way to get started is to record the macro
to perform the operation once, then alter the macro to accommodate the
rest of the files. Additionally, you may need to have 2 files open at
once: the "master" file that holds the imported text files, and a
"temporary" file that imports the text file. The macro may need to
switch from one file to the other to move the imported tab from the
temporary file to the master, and then close the temporary file.
You can post your code to this newsgroup for debugging assistance.



minhao

Sorry , this should be the correct macro.

Sub Movesheet()
'
' Movesheet Macro
'
'

'
Windows("04120803.txt").Activate
Sheets("04120803").Select
Sheets("04120803").Move Befo=Workbooks("root.xls").Sheets(1)
Windows("04120802.txt").Activate
Sheets("04120802").Select
Sheets("04120802").Move Befo=Workbooks("root.xls").Sheets(1)
Windows("04120801.txt").Activate
Sheets("04120801").Select
Sheets("04120801").Move Befo=Workbooks("root.xls").Sheets(1)
End Sub

"minhao" wrote:

Hi Dave
Thanks for your reply
I have recorded the macro to move a sheet from the txt file to a root file.

How do I program it to move all the txt files to the root file?
I have named the file in such a way that the last two digits are in a
running series.
For example 04120801, 04120802,....04120899

Minhao


Sub Movesheet()
'
' Movesheet Macro
'

'
Sheets("04120802").Select
Sheets("04120802").Move Befo=Workbooks("root.xls").Sheets(1)
End Sub


"Dave O" wrote:

It can be done, and the best way to get started is to record the macro
to perform the operation once, then alter the macro to accommodate the
rest of the files. Additionally, you may need to have 2 files open at
once: the "master" file that holds the imported text files, and a
"temporary" file that imports the text file. The macro may need to
switch from one file to the other to move the imported tab from the
temporary file to the master, and then close the temporary file.
You can post your code to this newsgroup for debugging assistance.




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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com