VB for Applications, code error when running from sharepoint

Craig P 1 Reputation point
2022-11-18T19:49:26.013+00:00

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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,916 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 36,421 Reputation points Microsoft Vendor
    2022-11-21T01:45:42.743+00:00

    Hi @Craig P
    Since our forum focus on sharepoint development with c# and your issue is about sharepoint development with vba. I will recommend you to go techcommunity for more profeesional answers and advice. This is a Microsoft dedicated forum for VBA. Here is the link for you
    https://techcommunity.microsoft.com/


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.