We have migrated some docs to Sharepoint, but still need to run a VB script. I've updated the ChDir to (ActiveDocument.AttachedTemplate.Path) and that now resolves. But having a problem with Open strFile For Input As #1. Looking for ideas please... Thanks
The Script
Private Sub Document_Close()
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
End Sub
Private Sub Document_Open()
Dim strFileName As String
Dim strDBName As String
Dim strTabName As String
ChDrive "S"
'DB is in current folder
ChDir (ActiveDocument.AttachedTemplate.Path)
'DB is in parent folder
'ChDir (ActiveDocument.Path & "\..")
strCurDir = CurDir
''EDIT BELOW 2 LINES ONLY
strFileName = ImportVariable(strCurDir + "\settings.txt")
strTabName = "NEW DB"
''EDIT ABOVE 2 LINES ONLY
strLongName = strCurDir + "\" + strFileName
strSQL = "SELECT * FROM `'" & strTabName & "$'`"
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
ActiveDocument.MailMerge.OpenDataSource Name:= _
strLongName, ReadOnly:=False, LinkToSource:=True, _
Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=" + strFileName + ";Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=35;Jet OLEDB:Databas" _
, SQLStatement:=strSQL, _
SubType:=wdMergeSubTypeAccess
ActiveDocument.MailMerge.ViewMailMergeFieldCodes = wdToggle
End Sub
Private Function ImportVariable(strFile As String) As String
Open strFile For Input As #1