ravi kumar

I have created a macro in MS.Word. The following macro
will open the text file and reformat the page layout font
size, and whetere there is a * it will be replaced with a
manual page break. And finally the document will be
saved as word document.

Sub N9FB0550_REPORT()
' N9FB0550_REPORT Macro
' Macro recorded 2004-08-17 by AnapanaR
ChangeFileOpenDirectory "D:\"
Documents.Open FileName:="N9FB0550_REPORT.TXT",
ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
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 = 8
Selection.Font.Size = 7.5
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
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 =
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.TypeText Text:=vbTab & vbTab
NormalTemplate.AutoTextEntries("Page X of Y").Insert
Where:=Selection. _
Selection.MoveLeft Unit:=wdWord, Count:=7
Selection.MoveRight Unit:=wdCharacter, Count:=16,
Selection.Font.Size = 10
ActiveWindow.ActivePane.View.SeekView =
FileName:="D:\N9FB0550_REPORT.doc", FileFormat:= _
wdFormatDocument, LockComments:=False,
Password:="", AddToRecentFiles:= _
True, WritePassword:="",
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False,
SaveFormsData:=False, _

End Sub

Also in my ms-access application I am running this module
to call the macro.

Private Sub Convert_N9FB1050_Report()

Dim WD As Object

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

End Sub

Since I have N number of reports in my I wanted to use one
common macro to convert all the text files to word

Appreciate your help.

With Best Regards
Ravi Kumar

Douglas J. Steele

You don't seem to have a question in what you posted!

Are you saying that you want to know how to loop through all text documents
in a folder?

Private Sub Convert_N9FB1050_Report()

Dim WD As Object
Dim strFile As String
Dim strFolder As String

Set WD = CreateObject("Word.Application")
strFolder = "D:\"
strFile = Dir$(strFolder & "*.txt")
Do While Len(strFile) > 0
WD.Documents.Open strFolder & strFile
WD.Run "N9FB1050_REPORT"
strFile = Dir$()

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