In my active workbook ‘Service Providers’, I have a sheet named Notes. Using a button, I…
- User
In my active workbook ‘Service Providers’, I have a sheet named Notes. Using a button, I would like to open an excel sheet window that is 500 high 800 wide. When I enter values into the cells in this window, it will automatically save the values to my sheet ‘Notes’ in my active workbook ‘Service Providers’. Also when I open this window, the values in sheet ‘Notes’ will be displayed in the same cells of the open window.
- Assistant
To achieve this, you can follow the below steps:
- Insert a button in the sheet 'Notes' by going to the Developer tab and selecting 'Insert' -> 'Button'.
- Right-click on the button and select 'Assign Macro'.
- In the 'Assign Macro' window, click on 'New' to create a new macro.
- In the VBA editor that opens up, paste the following code:
Sub OpenNotesWindow() Dim NotesWindow As Workbook Dim NotesSheet As Worksheet Set NotesWindow = Workbooks.Add Set NotesSheet = NotesWindow.Worksheets(1) With NotesWindow .Title = "Notes" .WindowState = xlNormal .Height = 500 .Width = 800 End With NotesSheet.Range("A1").Value = ThisWorkbook.Worksheets("Notes").Range("A1").Value NotesSheet.Range("A2").Value = ThisWorkbook.Worksheets("Notes").Range("A2").Value 'copy and paste this line for the rest of the cells you want to display NotesWindow.Visible = True End Sub - User
Object dosent support this property or method on this line: .WindowState = xlNormal
- Assistant
I apologize for the error in my previous response. As a language model AI, I am not able to run VBA code so there might be some errors in my code, which I unable to check my code's syntax. I understand that the error occurred on the line ".WindowState = xlNormal".
This error occurs because the WindowState property can only be used for the Application object, not for a Workbook object. To set the state of a Workbook, you should use the Windows property instead.
Here's the modified code for the OpenNotesWindow sub:
Sub OpenNotesWindow() Dim NotesWindow As Workbook Dim NotesSheet As Worksheet Set NotesWindow = Workbooks.Add Set NotesSheet = NotesWindow.Worksheets(1) With NotesWindow.Windows(1) .WindowState = xlNormal .Height = 500 .Width = 800 End With NotesSheet.Range("A1").Value = ThisWorkbook.Worksheets("Notes").Range("A1").Value NotesSheet.Range("A2").Value = ThisWorkbook.Worksheets("Notes").Range("A2").Value 'copy and paste this line for the rest of the cells you want to display NotesWindow.Visible = True End SubI hope this resolves the error you were facing. Let me know if you need any further assistance.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.