Convert Text Files as Word Documents

A

ANAPANA RAVI KUMAR

Currently I am using MS-Access. I have created some
macro N9FB1090_REPORT on MS-Word and running the
following code to run the Macrousing my ms-access module
to convert text file to word document.

Now the issue is I may have 10 to 100 TEXT files and I
wants to use of one macro to convert all the text files to
word documents


I have foudn some sample code from MSDN.COM

From the following I found how to get the file names and
number of files.

Can you pls suggest how to make use of my macro to create
equivalent word documents .

Appreciate your help.

Private Sub ShowFileList()

Dim File_Name As String



Set fs = Application.FileSearch
With fs
.LookIn = "D:\"
.FileName = "N9FB10*.TXT"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
File_Name = .FoundFiles(i)
MsgBox "File_Name -> " & File_Name
Next i
Else
MsgBox "There were no files found."
End If
End With


End Sub



Running Macro in MS-Access application:

Public Sub Convert_N9FB1090_Report()

Dim WD As Object

Set WD = CreateObject("Word.Application")
WD.Documents.Open "D:\N9FB1090_REPORT.TXT"
WD.Run "N9FB1090_REPORT"

End Sub


Word Macro
Sub N9FB1090_REPORT()
'
' N9FB1090_REPORT Macro
' Macro recorded 2004-08-25 by AnapanaR
'
ChangeFileOpenDirectory "D:\"
Documents.Open FileName:="N9FB1090_REPORT.TXT",
ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
Selection.WholeStory
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.92)
.BottomMargin = InchesToPoints(0.92)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.GutterPos = wdGutterPosLeft
End With
Selection.Font.Size = 7
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*"
.Replacement.Text = "^m"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
Selection.TypeText Text:="Caterpillar Asia Pte Ltd" &
vbTab & vbTab & _
"Confidential: Green"
Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Size = 8
Selection.MoveDown Unit:=wdLine, Count:=1
NormalTemplate.AutoTextEntries("Filename and
path").Insert Where:= _
Selection.Range
Selection.TypeText Text:=vbTab & vbTab
NormalTemplate.AutoTextEntries("Page X of Y").Insert
Where:=Selection. _
Range
Selection.MoveLeft Unit:=wdWord, Count:=7
Selection.MoveRight Unit:=wdCharacter, Count:=16,
Extend:=wdExtend
Selection.Font.Size = 10
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
ActiveDocument.SaveAs
FileName:="D:\N9FB1090_REPORT.doc", FileFormat:= _
wdFormatDocument, LockComments:=False,
Password:="", AddToRecentFiles:= _
True, WritePassword:="",
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveDocument.Close

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top