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 change the code below to use the address values in the 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 address values from the "Links Page" sheet in your code, you can retrieve the values from the cells and concatenate them together to form the file path. Here's an example:
Dim wb As Workbook Dim ws As Worksheet Dim serviceProvidersValue As String Dim pathValue As String Dim filePath As String Set wb = ThisWorkbook Set ws = wb.Sheets("Links Page") serviceProvidersValue = ws.Range("A2").Value pathValue = ws.Range("B2").Value filePath = pathValue & "SrvPlnJulAug.docm" Set wdDoc = wdApp.Documents.Open(filePath)In this code, we retrieve the values from the cells A2 and B2 of the "Links Page" sheet and store them in the
serviceProvidersValueandpathValuevariables, respectively. Then, we concatenate thepathValuewith the filename "SrvPlnJulAug.docm" to form thefilePath. Finally, we pass thefilePathto theDocuments.Openmethod to open the Word document. - User
If I do not want to use filePath, will this work; ' Set wdDoc = wdApp.Document.Open(pathValue & "SrvPlnJulAug.docm" '
- Assistant
Yes, you can directly pass the concatenation of
pathValueand the filename "SrvPlnJulAug.docm" to theDocuments.Openmethod to open the Word document. Here's the updated code:Dim wb As Workbook Dim ws As Worksheet Dim serviceProvidersValue As String Dim pathValue As String Set wb = ThisWorkbook Set ws = wb.Sheets("Links Page") serviceProvidersValue = ws.Range("A2").Value pathValue = ws.Range("B2").Value Set wdDoc = wdApp.Documents.Open(pathValue & "SrvPlnJulAug.docm")This code eliminates the use of the
filePathvariable and directly opens the document using the concatenation ofpathValueand the filename "SrvPlnJulAug.docm" within theDocuments.Openmethod.