Convert text file (.txt) to html file
Hi,
I am having bunch of text files (*.txt) which i need to convert to html files (.htm). How to do this?
For e.g. There were nearly about 1,000 files in a specified path c:\text\*.txt, which i need to convert all the files into html file with a same file name.
Please help.
Thanks,
Shanmugam
Batch Convert txt to html + happy and sunny day
Quote:
Originally Posted by Shanmugam
Hi,
I am having bunch of text files (*.txt) which i need to convert to html files (.htm). How to do this?
For e.g. There were nearly about 1,000 files in a specified path c:\text\*.txt, which i need to convert all the files into html file with a same file name.
Please help.
Thanks,
Shanmugam
Try this Shanmugam
create empty word document, store VBA code (ALT+F11)
and prepare input and output directories directory, run code (ALT+F8)
C:\WordTest\input\ (for *.txt files)
C:\WordTest\output\ (for *.html files)
happy and sunny day
Om Prakash
Pavel Humenuk
Sub LoopThroughFilesInFolder()
Dim i As Integer
Dim docDoc As Document
Dim myVar As String
myVar = "C:\WordTest\output\"
With Application.FileSearch
.LookIn = "c:\WordTest\input\"
.FileName = "*.txt"
.Execute
For i = 1 To .FoundFiles.Count
' Message box for informational purposes only
MsgBox "File #" & i & " is " & .FoundFiles(i)
'opens files individually
Set docDoc = Documents.Open(FileName:=.FoundFiles(i))
'change the doc and save it
'docDoc.Range.InsertAfter "test"
'docDoc.SaveAs FileName = test1a.htm, FileFormat:=wdFormatHTML
'docDoc.SaveAs FileName:=myVar & docDoc, FileFormat:=wdFormatRTF
docDoc.SaveAs FileName:=myVar & docDoc, FileFormat:=wdFormatHTML
'docDoc.SaveAs FileName:=myVar & docDoc, FileFormat:=wdFormatWebArchive ' OR TRY THIS
'docDoc.SaveAs FileName = test1a.htm, FileFormat:=wdFormatRTF
docDoc.Close (wdSaveChanges)
Next i
End With
End Sub
Batch Convert txt to html with new file extension + good night
Quote:
Originally Posted by Shanmugam
Hi,
I am having bunch of text files (*.txt) which i need to convert to html files (.htm). How to do this?
For e.g. There were nearly about 1,000 files in a specified path c:\text\*.txt, which i need to convert all the files into html file with a same file name.
Please help.
Thanks,
Shanmugam
Try this Shanmugam
create empty word document, store VBA code (ALT+F11)
and prepare input and output directories directory, run code (ALT+F8)
C:\WordTest\input\ (for *.txt files)
C:\WordTest\output\ (for *.html files)
sorry, me forget new file extension :-)
happy and sunny day and good night
Om Prakash
Pavel Humenuk
Sub LoopThroughFilesInFolder()
Dim i As Integer
Dim docDoc As Document
Dim myVar As String
myVar = "C:\WordTest\output\"
With Application.FileSearch
.LookIn = "c:\WordTest\input\"
.FileName = "*.txt"
.Execute
For i = 1 To .FoundFiles.Count
' Message box for informational purposes only
MsgBox "File #" & i & " is " & .FoundFiles(i)
'opens files individually
Set docDoc = Documents.Open(FileName:=.FoundFiles(i))
FileName = Mid(docDoc, 1, Len(docDoc) - 4) & ".html"
'change the doc and save it
'docDoc.Range.InsertAfter "test"
'docDoc.SaveAs FileName = test1a.htm, FileFormat:=wdFormatHTML
'docDoc.SaveAs FileName:=myVar & FileName, FileFormat:=wdFormatRTF
docDoc.SaveAs FileName:=myVar & FileName, FileFormat:=wdFormatHTML
'docDoc.SaveAs FileName:=myVar & FileName, FileFormat:=wdFormatWebArchive ' OR TRY THIS
'docDoc.SaveAs FileName = test1a.htm, FileFormat:=wdFormatRTF
docDoc.Close (wdSaveChanges)
Next i
End With
End Sub
Problem with the supplied code
Quote:
Originally Posted by hardlife
Try this Shanmugam
create empty word document, store VBA code (ALT+F11)
and prepare input and output directories directory, run code (ALT+F8)
C:\WordTest\input\ (for *.txt files)
C:\WordTest\output\ (for *.html files)
sorry, me forget new file extension :-)
happy and sunny day and good night
Om Prakash
Pavel Humenuk
Sub LoopThroughFilesInFolder()
Dim i As Integer
Dim docDoc As Document
Dim myVar As String
myVar = "C:\WordTest\output\"
With Application.FileSearch
.LookIn = "c:\WordTest\input\"
.FileName = "*.txt"
.Execute
For i = 1 To .FoundFiles.Count
' Message box for informational purposes only
MsgBox "File #" & i & " is " & .FoundFiles(i)
'opens files individually
Set docDoc = Documents.Open(FileName:=.FoundFiles(i))
FileName = Mid(docDoc, 1, Len(docDoc) - 4) & ".html"
'change the doc and save it
'docDoc.Range.InsertAfter "test"
'docDoc.SaveAs FileName = test1a.htm, FileFormat:=wdFormatHTML
'docDoc.SaveAs FileName:=myVar & FileName, FileFormat:=wdFormatRTF
docDoc.SaveAs FileName:=myVar & FileName, FileFormat:=wdFormatHTML
'docDoc.SaveAs FileName:=myVar & FileName, FileFormat:=wdFormatWebArchive ' OR TRY THIS
'docDoc.SaveAs FileName = test1a.htm, FileFormat:=wdFormatRTF
docDoc.Close (wdSaveChanges)
Next i
End With
End Sub
I tried this approach, but get an run time error 13 on this line:
Set docDoc = Documents.Open(FileName:=.FoundFiles(i))
I set a reference to the Microsoft Word Object library.
Is there some other reference required?????
Are you running this code directly from word ?
Quote:
Originally Posted by orange
I tried this approach, but get an run time error 13 on this line:
Set docDoc = Documents.Open(FileName:=.FoundFiles(i))
I set a reference to the Microsoft Word Object library.
Is there some other reference required?????
May be you are not running code directly from word.
create empty WORD document, store VBA code (ALT+F11)
and prepare input and output directories directory, run code (ALT+F8)
hope this helps
HAPPY WINTER DAY
Pavel Humenuk
Please try run this code directly from word
Quote:
Originally Posted by orange
Pavel,
I am trying to run the code from Access 2003.
I am now getting an error on the File Save
It says I'm tring to save a file with the name of a file that is already open????
Try run this code directly from word,
because I am not skilled enough to
run it from Access.
Me is wishing you good luck, Pavel