thebiped
01-13-2017, 02:31 PM
So the place I work for is using Word 2010 but alot of the code they use was office 2003 code. I am a network engineer so I can script routers and do VLSM subnets all day long but coding software and VBA code is out of my wheelhouse. I understand a little C++ that I took in college but I've never really messed with this kind of code before. I am not really understanding how to use the DIR in this code and ANY help would be greatly appreciated from the gurus here. I realize that there are other threads with this but I didn't know how you guys felt about raising old threads form the dead.
***EDIT*** I guess i should state the problem is with the Application.FileSearch portion of this code. It's no longer supported by 2010...not that you all didn't know that but I'm doing my best to be as helpful as possible to the folks helping me.
Sub MergeSetup()
'
' MergeSetup Macro
' This macro sets up the header source containt the field
' list and the data source file containg the source fields.
'
' Note this macro should be executed when the "Forms Gen" document
' is created. This sets the mail merege properties for the document and
' allows for the painting of the forms document.
'
' History
' 03/02/98 Rob Berringer Initial Creation
' 07/10/98 Rob Berringer Added Addtional Error Trapping.
'
' Check for required files.
Set FileSrch = Application.FileSearch
With FileSrch
.LookIn = "C:\windows"
.SearchSubFolders = False
.FileName = "tokens.tkn"
.MatchTextExactly = True
If .Execute = 0 Then
MsgBox "Tokens File Not Found, Required for Merge Setup", Title:="Court View 2000"
GoTo cleanExit ' Get out
End If
.FileName = "crth6005.dat"
If .Execute = 0 Then
MsgBox "Data File Not Found, Required for Merge Setup", Title:="Court View 2000"
GoTo cleanExit ' Get out
End If
End With
MsgString = "Setup Merge Files For The Document. This function should " & _
"only be peformed at the initial setup of the Document"
If MsgBox(MsgString, vbOKCancel, Title:="Court View 2000") = vbOK Then
' Set up the merge document as a Form Letter
On Error GoTo errorCatch
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
' Set Header from Token file.
ActiveDocument.MailMerge.OpenHeaderSource Name:="C:\WINDOWS\TOKENS.TKN", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto
' Set Source file from Dat File.
ActiveDocument.MailMerge.OpenDataSource Name:="C:\WINDOWS\CRTH6005.DAT", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1 _
:=""
' OK Start Building the Form (Start User Edit)
ActiveDocument.MailMerge.EditMainDocument
' Complete Message
StrMessage = "Merge File Setup is Complete. " & _
"Build Forms Generation Document"
MsgBox StrMessage, Title:="Court View 2000"
End If
' Exit, Jump out
GoTo cleanExit
errorCatch:
MsgString = "Setup Aborted, Merge File Setup is Not Complete:"
MsgBox MsgString, Title:="Court View 2000"
cleanExit:
End Sub
***EDIT*** I guess i should state the problem is with the Application.FileSearch portion of this code. It's no longer supported by 2010...not that you all didn't know that but I'm doing my best to be as helpful as possible to the folks helping me.
Sub MergeSetup()
'
' MergeSetup Macro
' This macro sets up the header source containt the field
' list and the data source file containg the source fields.
'
' Note this macro should be executed when the "Forms Gen" document
' is created. This sets the mail merege properties for the document and
' allows for the painting of the forms document.
'
' History
' 03/02/98 Rob Berringer Initial Creation
' 07/10/98 Rob Berringer Added Addtional Error Trapping.
'
' Check for required files.
Set FileSrch = Application.FileSearch
With FileSrch
.LookIn = "C:\windows"
.SearchSubFolders = False
.FileName = "tokens.tkn"
.MatchTextExactly = True
If .Execute = 0 Then
MsgBox "Tokens File Not Found, Required for Merge Setup", Title:="Court View 2000"
GoTo cleanExit ' Get out
End If
.FileName = "crth6005.dat"
If .Execute = 0 Then
MsgBox "Data File Not Found, Required for Merge Setup", Title:="Court View 2000"
GoTo cleanExit ' Get out
End If
End With
MsgString = "Setup Merge Files For The Document. This function should " & _
"only be peformed at the initial setup of the Document"
If MsgBox(MsgString, vbOKCancel, Title:="Court View 2000") = vbOK Then
' Set up the merge document as a Form Letter
On Error GoTo errorCatch
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
' Set Header from Token file.
ActiveDocument.MailMerge.OpenHeaderSource Name:="C:\WINDOWS\TOKENS.TKN", _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
wdOpenFormatAuto
' Set Source file from Dat File.
ActiveDocument.MailMerge.OpenDataSource Name:="C:\WINDOWS\CRTH6005.DAT", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1 _
:=""
' OK Start Building the Form (Start User Edit)
ActiveDocument.MailMerge.EditMainDocument
' Complete Message
StrMessage = "Merge File Setup is Complete. " & _
"Build Forms Generation Document"
MsgBox StrMessage, Title:="Court View 2000"
End If
' Exit, Jump out
GoTo cleanExit
errorCatch:
MsgString = "Setup Aborted, Merge File Setup is Not Complete:"
MsgBox MsgString, Title:="Court View 2000"
cleanExit:
End Sub