My workbook 'Service Providers.xlsm' is in a folder named 'SERVICE PROVIDERS' I have a…
- User
My workbook 'Service Providers.xlsm' is in a folder named 'SERVICE PROVIDERS' I have a sub folder named 'zzzz ServProvDocs' in the same folder named 'SERVICE PROVIDERS'
The following code in my workbook is giving me a path error;
Sub OpenPremAssHalfDaySchedule() Dim waasch As Workbook Set waasch = Workbooks.Open("zzzz ServProvDocs\Premises Staff Schedules\TasksTodayAA.xlsm") waasch.Activate End Sub
- Assistant
The path error is occurring because you need to provide the full path for the subfolder "zzzz ServProvDocs" in your code. Update your code as follows:
Sub OpenPremAssHalfDaySchedule() Dim folderPath As String Dim filePath As String Dim waasch As Workbook
' Get the full path to the folder folderPath = ThisWorkbook.Path & "\zzzz ServProvDocs\" ' Build the full file path filePath = folderPath & "Premises Staff Schedules\TasksTodayAA.xlsm" ' Open the workbook Set waasch = Workbooks.Open(filePath) ' Activate the workbook waasch.ActivateEnd Sub
This code will concatenate the workbook's current path with the subfolder path and file name, ensuring that you provide the full, correct path to open the workbook.