I have the following wordbasic (word 97) code that I needed to convert
to
VBA or (VB.NET). Basically, this code combines all documents in a
folder as a master document in order to print it. Any help on
this..Thank you.
WordBasic.FileOpen Name:=DOCNAME$
WordBasic.EndOfDocument
WordBasic.InsertPara
WordBasic.ViewMasterDocument
WHILE NOT EOF
WordBasic.InsertSubdocument Name:=DOCNAME$, ReadOnly:=1, Revert:=1
WordBasic.EndOfDocument
Wend
Doug Robbins - Word MVP - 15 Feb 2007 20:33 GMT
Take a look at the following:
If you put all of the documents in a folder by themselves, a macro
containing the following code should insert each of them into a new document
in the date order:
Dim MyPath As String
Dim MyName As String
Dim Source As Document, Target As Document
Dim SourceFile As Range
Dim i As Long
Dim FileList As Document
Set FileList = Documents.Add
'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With
'strip quotation marks from path
If Len(MyPath) = 0 Then Exit Sub
If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
Selection.InsertAfter MyName & vbCr
MyName = Dir
Loop
'Sort the list of files
FileList.Range.Sort SortFieldType:=wdSortFieldAlphanumeric,
FieldNumber:="Paragraphs"
'Delete the empty paragraph that will be at the top of the list of files
FileList.Paragraphs(1).Range.Delete
'Start a new document into which each of the others will be inserted
Set Target = Documents.Add
'Iterate through the list of files, getting the name of each file, opening
it
'and inserting its contents into the Target document
For i = 1 To FileList.Paragraphs.Count
Set SourceFile = FileList.Paragraphs(i).Range
SourceFile.End = SourceFile.End - 1
Set Source = Documents.Open(MyPath & SourceFile.Text)
Target.Range.InsertAfter Source.Range.FormattedText
Source.Close wdDoNotSaveChanges
Next i
Also see the article "Print all documents in a given folder to a single
print file" at:
http://www.word.mvps.org/FAQs/MacrosVBA/PrintAllDocsInFldr.htm

Signature
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
> I have the following wordbasic (word 97) code that I needed to convert
> to
[quoted text clipped - 10 lines]
> WordBasic.EndOfDocument
> Wend
c_shah - 16 Feb 2007 18:47 GMT
Perry - 18 Feb 2007 11:50 GMT
> I have the following wordbasic (word 97) code that I needed to convert
> to
> VBA or (VB.NET).
This is a VB.net example, running through directories and getting filenames.
The point in which y´ve retrieved file information is indicated by remark <<
actionpoint
Here you can print or do whatever you want with filename as retrieved.
Private Sub SomeSubroutine()
'enter the rootfolder you want to inspect
Dim di As DirectoryInfo = New DirectoryInfo("c:\data\MyRootfolder")
GetFiles(di)
End Sub
Private Sub GetFiles(ByVal InspFolder As DirectoryInfo)
Dim sMsg As String = ""
Try
For Each fi As FileInfo In InspFolder.GetFiles
sMsg = "Filename: " + fi.Name + vbCr
sMsg += "Date modified: " + fi.LastWriteTime + vbCr
sMsg += "Parent: " + InspFolder.FullName
Next
Catch ex As Exception
sMsg = "Error accessing folder:" + vbCr
sMsg += InspFolder.FullName
End Try
'now a messagebox output but
'you can perform the action to the file y've retrieved
MessageBox.Show(sMsg) '<< actionpoint
For Each dir As DirectoryInfo In InspFolder.GetDirectories
GetFiles(dir) '<< Recurse
Next
End Sub
--
Krgrds,
Perry
System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
> I have the following wordbasic (word 97) code that I needed to convert
> to
[quoted text clipped - 10 lines]
> WordBasic.EndOfDocument
> Wend
Perry - 18 Feb 2007 12:00 GMT
Sorry, the action point should be hosted in this part of the previously
posted code±
For Each fi As FileInfo In InspFolder.GetFiles
sMsg = "Filename: " + fi.Name + vbCr
sMsg += "Date modified: " + fi.LastWriteTime + vbCr
sMsg += "Parent: " + InspFolder.FullName
´this is the action point to print or do what ever you like with the
file
´<< your code goes here >>
Next
--
Krgrds,
Perry
System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
>> I have the following wordbasic (word 97) code that I needed to convert
>> to
[quoted text clipped - 56 lines]
>> WordBasic.EndOfDocument
>> Wend