Consulting

Results 1 to 3 of 3

Thread: I need help in a bad way

  1. #1
    VBAX Newbie
    Joined
    Jan 2017
    Posts
    1
    Location

    I need help in a bad way

    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

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    For an Application.FileSearch replacement, see the discussion at:
    http://answers.microsoft.com/en-us/o...8-84f28300dba4
    You can download the class module from: http://dl.dropbox.com/u/35239054/FileSearch.cls
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    As an alternative, you could just pass your required files (full path) to function that returns a Boolean True\False result:

    Function fcnFileOrDirExists(PathName As String) As Boolean
    'Macro Purpose: Function returns TRUE if the specified file or folder exists, false if not.
    'PathName: Supports Windows mapped drives
    'File usage: Provide full file path and extension
    'Folder usage : Provide full folder path
    Dim iTemp As Integer
      'Ignore errors to allow for error evaluation
      On Error Resume Next
      iTemp = GetAttr(PathName)
      'Check if error exists and set response appropriately
      Select Case Err.Number
        Case Is = 0: fcnFileOrDirExists = True
      Case Else: fcnFileOrDirExists = False
      End Select
      'Resume error checking
      On Error GoTo 0
    lbl_Exit:
      Exit Function
    End Function
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •