Word VBA .FileSearch Replacement attempt...

  • Hi guys,

    I am more of an excel VBA guy and I am having an issue with below macro to attach templates to Word Documents in the same folder as an open file. The issue has arisen when testing the new office and finding out .FileSearch has been removed.
    The code seems to work in excel (when I change .docx to .xls) but in word I'm having issues with the sPath Dim.
    Any assistance would be greatly appreciated.

    Joe


  • Re: Word VBA .FileSearch Replacement attempt...


    Hi Joe,
    I believe both Word and Excel have the FullName property ie,
    ActiveDocument.FullName for Word
    ActiveWorkBook.FullName for Excel


    The FullName includes the path name which is what I think you are after. To extract just the path name out of the FullName property you could use something like:

    Code
    Function JustPathName(sFullPath As String) As String
      JustPathName = ""
      If InStrRev(sFullPath, "\") = 0 Then Exit Function
      
      JustPathName = Left(sFullPath, InStrRev(sFullPath, "\"))
      Exit Function
    End Function

    So, using your example you would use:
    Set sPath = JustPathName(ActiveDocument.FullName)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!