I have a sheet called 'Links Page' that has the following details; A2 value = SERVICE…
- User
I have a sheet called 'Links Page' that has the following details; A2 value = SERVICE PROVIDERS B2 value = G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\zzzz ServProvDocs\
How should I write the code below to use the values in sheet 'Links Page'
Set wdDoc = wdApp.Documents.Open("G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\zzzz ServProvDocs\SrvPlnJulAug.docm")
- Assistant
To use the values from the 'Links Page' sheet in your VBA code, you can update the code as follows:
VBADim serviceProviders As String Dim filePath As String ' Set the values from 'Links Page' sheet serviceProviders = ThisWorkbook.Worksheets("Links Page").Range("A2").Value filePath = ThisWorkbook.Worksheets("Links Page").Range("B2").Value ' Append the file name to the file path Dim fileName As String fileName = "SrvPlnJulAug.docm" filePath = filePath & fileName ' Open the document using the file path and Word application Dim wdApp As Object Dim wdDoc As Object Set wdApp = CreateObject("Word.Application") Set wdDoc = wdApp.Documents.Open(filePath)In this updated code, the values from cells A2 and B2 in the 'Links Page' sheet are assigned to the variables and , respectively. Then, the file name "SrvPlnJulAug.docm" is appended to the file path using the operator. Finally, the document is opened using the updated filePath and the Word application.