Import data from multiple text files to multiple sheets in Excel

RagiTester

New Member
Joined
Dec 22, 2010
Messages
17
Hi,I am looking for Excel VB code where i can import data from multiple text(notepad) files into multiple worksheets of a new excel workbook. Also the name of the tabs should be as the names of the text files.Any Suggestions???
 
The following line will pause the macro for 5 seconds (it's in hh:mm:ss format, so adjust as necessary):
Code:
Application.Wait Now + TimeValue("00:00:05")
This could help solve the problem you mentioned above, where the code works OK if you step through it, but not if it runs on its own, where the macro is interacting with external files.
Cindy
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
The following line will pause the macro for 5 seconds (it's in hh:mm:ss format, so adjust as necessary):
Code:
Application.Wait Now + TimeValue("00:00:05")
This could help solve the problem you mentioned above, where the code works OK if you step through it, but not if it runs on its own, where the macro is interacting with external files.
Cindy

Hi Cindy, thanks for the help.. the code is working pretty fine now.

One issue, if the user gives a wrong SOURCE path or DESTINATION path, the code gives an error.

I want that if the user gives a SOURCE PATH or DESTINATION PATH that is invalid (does not exist on the system), then the user should get an appropriate message and macro should end w/o any errors..
How to code for this.
 
Upvote 0
Can you post the code you have so far? The best way to address that will depend on the approach you're using.
 
Upvote 0
Can you post the code you have so far? The best way to address that will depend on the approach you're using.

Hi,
Now my macro is working fine..

I want a running clock (hh:mm:ss) to be displayed on the excel with start - stop button.
Any suggestions?
 
Upvote 0
Apparently putting a running timer on a worksheet that will be edited isn't particularly simple. I found the following by searching the MrExcel forum for the word "timer". The linked thread discusses the problem and a solution, but it displays the current time rather than elapsed time, and the time disappears when the stop button is pressed.
http://www.mrexcel.com/forum/showpost.php?p=1949222&postcount=3
I have modified the code just a bit for your needs, but it has certain limitations. As written here, it displays elapsed time in cell A1, and uses a cell assumed to be out of range of your existing workbook, cell AB1, to hold the time that the start button was pressed, so that Cell A1 shows elapsed time rather than current time.
When the Stop button is pressed, it freezes the elapsed time in the cell. If you need to use different cells for this, you will need to adjust the parts shown in Red. I have tested this a bit, but certainly not within your application. Since this isn't my code, I won't be able to help much if it doesn't work.
Code:
Global myStartTime As Double
Private Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerfunc As Long) As Long
 
Private Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
 
Private lTimerId As Long
Private oTargetCell As Range
Private Sub TimerProc()
 
    On Error Resume Next
    oTargetCell.Calculate
 
End Sub
 
Sub AddClock(Cell As Range)
 
    Set oTargetCell = Cell
    Cell.FormulaR1C1 = "=TEXT(NOW() [COLOR=red]-RC[27][/COLOR],""hh:mm:ss"")"
    lTimerId = SetTimer(0, 0, 100, AddressOf TimerProc)
 
End Sub
 
Sub RemoveClock(Cell As Range)
 
    KillTimer 0, lTimerId
    Cell.FormulaR1C1 = Cell.Value
 
End Sub
 
 
Sub CreateClock()
 
    Range("[COLOR=red]AB1[/COLOR]").Value = Now()  'this should be a cell that's outside your used data range
    AddClock Range("[COLOR=red]a1[/COLOR]")
 
End Sub
Sub DestroyClock()
 
    RemoveClock Range("[COLOR=red]a1[/COLOR]")
 
End Sub

To use this, put the code into a standard module, then add 2 buttons to your worksheet (From the developer tab, choose Insert, then choose the button element to draw the button.) Link the Start button to the macro CreateClock, and the Stop button to the macro DestroyClock.

Hope this helps,
Cindy
 
Last edited:
Upvote 0
Apparently putting a running timer on a worksheet that will be edited isn't particularly simple. I found the following by searching the MrExcel forum for the word "timer". The linked thread discusses the problem and a solution, but it displays the current time rather than elapsed time, and the time disappears when the stop button is pressed.
http://www.mrexcel.com/forum/showpost.php?p=1949222&postcount=3
I have modified the code just a bit for your needs, but it has certain limitations. As written here, it displays elapsed time in cell A1, and uses a cell assumed to be out of range of your existing workbook, cell AB1, to hold the time that the start button was pressed, so that Cell A1 shows elapsed time rather than current time.
When the Stop button is pressed, it freezes the elapsed time in the cell. If you need to use different cells for this, you will need to adjust the parts shown in Red. I have tested this a bit, but certainly not within your application. Since this isn't my code, I won't be able to help much if it doesn't work.
Code:
Global myStartTime As Double
Private Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerfunc As Long) As Long
 
Private Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
 
Private lTimerId As Long
Private oTargetCell As Range
Private Sub TimerProc()
 
    On Error Resume Next
    oTargetCell.Calculate
 
End Sub
 
Sub AddClock(Cell As Range)
 
    Set oTargetCell = Cell
    Cell.FormulaR1C1 = "=TEXT(NOW() [COLOR=red]-RC[27][/COLOR],""hh:mm:ss"")"
    lTimerId = SetTimer(0, 0, 100, AddressOf TimerProc)
 
End Sub
 
Sub RemoveClock(Cell As Range)
 
    KillTimer 0, lTimerId
    Cell.FormulaR1C1 = Cell.Value
 
End Sub
 
 
Sub CreateClock()
 
    Range("[COLOR=red]AB1[/COLOR]").Value = Now()  'this should be a cell that's outside your used data range
    AddClock Range("[COLOR=red]a1[/COLOR]")
 
End Sub
Sub DestroyClock()
 
    RemoveClock Range("[COLOR=red]a1[/COLOR]")
 
End Sub

To use this, put the code into a standard module, then add 2 buttons to your worksheet (From the developer tab, choose Insert, then choose the button element to draw the button.) Link the Start button to the macro CreateClock, and the Stop button to the macro DestroyClock.

Hope this helps,
Cindy

Hi Cindy,
My macro is working fine now.
The functionality is.. The user needs to give a Source Path and Destination path and run the macro

The macro will pick up all the text filles from source path and make a new excel import the data from text files into multiple sheets of new excel and name the sheets as per text files name and save it in the Destination path.

I have also given the facility of upload at a given time.
The user can schedule the macro to run at a particular time..

Thanks a lot for your guidance.

I am testing the tool now.. Hoping everything will work fine..
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top