Thread: Datasource
View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Datasource

If you put the documents in a separate folder and run the following macro,
then provided the documents are not password protected, the macro should
list the documents and their associated data sources in a new document. If
no data source is attached, the macro reports that also. Any automacros in
the documents are temporarily disabled and the documents are not altered..

Sub ListDataSources()
Dim strFile As String
Dim strPath As String
Dim oDoc As Document
Dim oTarget As Document
Dim iFld As Integer
Dim fDialog As FileDialog
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the documents and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) "\" Then strPath = strPath + "\"
End With
WordBasic.DisableAutoMacros 1
If Documents.Count 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
Set oTarget = Documents.Add
strFile = Dir$(strPath & "*.do?")
While strFile ""
Set oDoc = Documents.Open(strPath & strFile)
oTarget.Activate
Selection.TypeText oDoc.FullName & Chr(11)
If oDoc.MailMerge.MainDocumentType wdNotAMergeDocument Then
Selection.TypeText "Datasource: - " & oDoc.MailMerge.DataSource.name
Else
Selection.TypeText "Not a merge document"
End If
Selection.TypeParagraph
oDoc.Close SaveChanges:=wdDoNotSaveChanges
strFile = Dir$()
Wend
WordBasic.DisableAutoMacros 0
End Sub

http://www.gmayor.com/installing_macro.htm


--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org



Alex Hammerstein wrote:
Hi, Thanks for your response.

What I am trying to establish is that for a document that already has
a data source, is it possible to establish the name of the data
source without having to open the document. Its just that I have a
few hundred to check and I was hoping that I wouldn't have to go
through each one opening them up. I looked under properties but
couldn't see anything

Thanks

Alex



On 23/01/2009 10:59, in article ,
"Graham Mayor" wrote:

You can create a data source (e.g. with Excel or Access - or even
from the mailings tab (Select Recipients) of Word 2007 itself)
without opening the document with which it will be used, but in
order to attach it to the document the document needs to be opened.