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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search for and extract word from multiple documents 1

Status
Not open for further replies.

Jtorres13

Technical User
Nov 11, 2006
162
US
Hello. I have a question and not much time to come up with an answer.

we have a login script which extracts the name of the default printer for the logged on user. It comes out as \\computer name\printer name.

Every time user logs on, a .txt file is created with that user's default printer name. File is stored in a shared folder. Folder now has a few hundred of these .txt files.

I need to put together a single list with everyone's default printer. I néed to pull the \\computer name\default printer from every .txt and list of all of them in a single Word document or Excel spreadsheet.

Any ideas?
 
Try:
Code:
Sub Import_Text()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document, txtFile As Document
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.txt", vbNormal)
Set wdDoc = ActiveDocument
While strFile <> ""
  Set txtFile = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False, ConfirmConversions:=False)
  wdDoc.Range.InsertAfter txtFile.Range.Text & vbCr
  txtFile.Close SaveChanges:=True
  strFile = Dir()
Wend
Set txtFile = Nothing: Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

Cheers
Paul Edstein
[MS MVP - Word]
 
Thank you! After a few edits, I was able to do what I need to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top