I need a VBA code that can do the following: From my open workbook 'Service Provider'and…
- User
I need a VBA code that can do the following:
From my open workbook 'Service Provider'and active sheet, Open into the background the closed workbook 'Service Provider History' located at "G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\Service Providers History.xlsx". Copy cells with data in column J from J5 downwards from the sheet in workbook 'Service Provider History, that has the same name as the active sheet in workbook 'Service Provider' Open a new Note Pad sheet and paste each cell copied into a seprate line in Note Pad. Close workbook 'Service Provider History'
- Assistant
- User
error on this line of code: Set destinationWorkbook = Workbooks.Open(path & fileName)
- Assistant
If you are getting an error on the line
Set destinationWorkbook = Workbooks.Open(path & fileName), it could be due to one of the following reasons:-
File path or name is incorrect: Double-check the
pathandfileNamevariables to ensure that they match the actual file path and name of the 'Service Provider History' workbook. Make sure to include the file extension (.xlsx). -
File is not accessible: Make sure that you have the necessary permissions to access the file located at the specified path. If the file is locked or opened by another user, it may cause an error.
-
File is already open: Check if the 'Service Provider History' workbook is already open in Excel. If it is open, you do not need to open it again and can directly reference it using
Workbooks("Service Provider History.xlsx")or by its index.
You can also try debugging the code by adding a message box to display the
pathandfileNamevariables before the problematic line to check if they have the correct values.MsgBox "Path: " & path & vbCrLf & "File Name: " & fileName Set destinationWorkbook = Workbooks.Open(path & fileName) -
- User
Code opened 'Service Provider History', copied the data from Column J, opened Note Pad, but did not paste the copied data into Note Pad. When I closed notepad, the code continued and pasted the data into my active sheet in Workbook 'Service Provider'. The code should only paste into Note Pad.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.