I am having an error on this line - Set NotesSheet =…
- User
I am having an error on this line - Set NotesSheet = ServiceProviders.Worksheets("Notes") in the following code: Public Sub OpenNotesWindow() Dim NoteWindow As Workbook Dim ServiceProviders As Workbook Dim NoteSheet As Worksheet Dim NotesSheet As Worksheet
Set NotesWindow = Workbooks.Open("G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\Auxillary.xlsm") Set ServiceProviders = Workbooks.Open("G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\Service Providers.xlsm") Set NoteSheet = NotesWindow.Worksheets("Note") Set NotesSheet = ServiceProviders.Worksheets("Notes")
With NoteWindow.Windows(1) .DisplayWorkbookTabs = False .WindowState = xlNormal .Height = 500 .Width = 800 End With
NotesSheet.Range("A1").Value = ThisWorkbook.Worksheets("Note").Range("A1").Value NotesSheet.Range("A2").Value = ThisWorkbook.Worksheets("Note").Range("A2").Value 'copy and paste this line for the rest of the cells you want to display
NoteWindow.Windows(1).Visible = True End Sub
- Assistant
The error on that line is a typo - the variable name should be "NotesSheet" instead of "NoteSheet". The corrected line should be:
Set NotesSheet = ServiceProviders.Worksheets("Notes")
- User
What is the correct code for this: Set NotesSheet = Workbooks.Service Providers.Worksheets("Notes")
- Assistant
The correct code is:
Set ServiceProviders = Workbooks.Open("G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\Service Providers.xlsm") Set NotesSheet = ServiceProviders.Worksheets("Notes")In this code snippet, you are opening a workbook named "Service Providers.xlsm" located in the specified file path. The reference to the workbook is stored in the variable "ServiceProviders".
Then, you are setting the worksheet variable "NotesSheet" to refer to the worksheet named "Notes" in "ServiceProviders".
- User
How do I reference the Workbook 'Service Providers' and its sheet 'Notes'
- Assistant
To reference the workbook named 'Service Providers' and its sheet 'Notes', you can use the following code:
Dim wb As Workbook Dim ws As Worksheet Set wb = Workbooks("Service Providers.xlsm") Set ws = wb.Worksheets("Notes")This code defines two variables, "wb" for the "Service Providers.xlsm" workbook and "ws" for the "Notes" worksheet. The "Set" keyword is used to assign the reference to the variables.
You can then use the "wb" and "ws" variables to refer to the workbook and worksheet respectively. For example, to set the value of cell A1 in the "Notes" worksheet to "Hello World", you can use:
ws.Range("A1").Value = "Hello World"