View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
[email protected] ucanalways@gmail.com is offline
external usenet poster
 
Posts: 115
Default Changing a file extension

Macropod,

Thanks for the macro. It sure does help but I get the values in the
Msgbox.

How would I display the content in the worksheet instead of a Msgbox?

Range("A1").value = DataSet doesn't do the trick!

Please let me know

Thanks,
Kevin

On Apr 14, 5:34 pm, "macropod" wrote:
Hi Kevin,

Here's a simple macro to read a delimited text file named "MyLog.Log" in the current folder. All the values are stored in an array
from which you can populate your destination worksheet. With large amounts of data this approach will be significantly faster (and
less problematic) than renaming the files, opening them as worksheets then copying from there to your destination worksheet. I've
read over 12 million records into arrays this way.

Sub Readfile()
Dim Data() ' Array
Dim DataSet
Dim i As Integer
Dim j As Integer
DataSet = ThisWorkbook.Path & "\MyLog.Log"
If Dir(DataSet) < "" Then
i = 1
Open DataSet For Input As #1
Do Until EOF(1)
ReDim Preserve Data(4, i)
Input #1, Data(1, i), Data(2, i), Data(3, i), Data(4, i)
i = i + 1
Loop
Close #1
End If
DataSet = ""
For j = 1 to i - 1
DataSet = DataSet & vbCrLf & Data(1, j) & " " & Data(2, j)
Next
Msgbox DataSet
End Sub

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

wrote in ...
Macropod,


My macro uses


Set sh = Sheets("Sheet1")


So, its not working with *.log file. Now, I have to change the *.log
file to *.xls file.. I have no other option, I guess!


Kevin


On Apr 14, 4:38 pm, wrote:
Hi Macropod,


When I manually rename that *.log file to *.xls and open that excel
file, I find the excel file in good shape. I understand that this is
not possible in all cases but in this particular case, it works.


The *.log file has data in 4 column, which when opened in a excel
file, is arranged in A, B, C and D columns respectively. The macro I
have references the column A and B of the excel file. Since, I have a
*.log file, I am not sure how my macro would associate the columns in
the *.log file as A and B. I guess this is possible only if the log
file is changed into an excel file.


This being the case, per your reply, my macro should be able to read
the values from *.log file? I am going to give this a shot.


Cheers
Kevin


On Apr 14, 4:26 pm, "macropod" wrote:


Hi Kevin,


The file extension needn't affect your macro's ability to read the *.txt and *.log files' contents. In any event, changing the
extension doesn't turn the files into Excel files and could cause other problems. Plus, you'll still need to understand those
files'
structure and code accordingly.


Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------


wrote in ...
Hello group,


I have a macro to pull the values in row A and B of a workbook, to
another workbook. I have some values in the files that have *.txt and
*.log extension.


Is there any macro to change the extension of the file (*.txt and
*.log) to *.xls? Please let know.


Thanks,
Kevin