Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining files

Status
Not open for further replies.

mkov

Programmer
Sep 10, 2003
203
US
Is there a way with VBA to combine 2 files? Currently I am doing it with a batch file which works great for .txt files, but if I format a file as a .rtf, it does not work.

Here is what I have in my batch file:

copy f:\pdoxdata\blotter.txt+f:\pdoxdata\temp.txt f:\pdoxdata\blotter.txt
del f:\pdoxdata\temp.txt

What I have to do is print about 20 or so reports to a file and combine them into one file. What I am doing is creating a blank text file (blotter.txt) with code and then each report is exported as temp.txt. Once the report is created, I call the batch file and combine the 2 file into blotter.txt.

The problem is that the .txt file is not "pretty" enough for my boss. An .rtf file is what I want to create, but the batch file is not able to combine .rtf files, only .txt.

Thanks for your help.
 
mkov,
I don't think you will have much luck concatenating .rtf files through a dos command.

However, here's a little snippet I've been working on. In reality, it's quite a bit more complicated--inserts hyperlinks to FileNet images, and command buttons that delete specific rows from an Oracle database.

What I left for you takes a .txt file and puts it in a Word document (.doc). If you wanted to concatenate other lines (or files), all you would have to do is create a range that represented the doc.sentences.last object, then start using the rng.Insertafter method to add the new lines.

You will also find that if you want, you can open your rtf files with Word, and concatenate them directly into a single document. Just use the Open method of the Documents collection.

The only other thing is you need a reference to the MS Word Object Library in the Tools|References area.

Option Explicit
Public appW As New Word.Application
Public doc As Word.Document
Public rng As Range
Public strInFN As String
Public strOutFN As String

Private Sub cmdRun_Click()
OpenFiles
ProcFile
Close
doc.SaveAs strOutFN
appW.Quit
Set appW = Nothing
Set doc = Nothing
Set rng = Nothing
End
End Sub


Private Sub OpenFiles()

strInFN = "C:\WORDTEST\KARSLOADLOGReformatted.LOG"
strOutFN = "C:\WORDTEST\KARSLOADLOG.DOC"
Open strInFN For Input As #1
Set doc = appW.Documents.Add
appW.Visible = True
appW.Options.CheckGrammarAsYouType = False
appW.Options.CheckSpellingAsYouType = False
Options.CheckGrammarWithSpelling = False
doc.PageSetup.LeftMargin = 36
doc.PageSetup.RightMargin = 36
doc.PageSetup.TopMargin = 36
doc.PageSetup.BottomMargin = 36
Set rng = doc.Range
rng.Font.Name = "courier new"
rng.Font.Size = 8

End Sub



Private Sub ProcFile()
Dim strIn As String

Do While Not EOF(1)
Line Input #1, strIn
'Add the row of information and the <cr>
rng.InsertAfter &quot; &quot; & Right(strIn, Len(strIn) - 2)
rng.InsertAfter Chr(13)
loop

End Sub

Hope that helps.
Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top