gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
I would like to include in a VBA module, an event that will copy A1:C28 to a new notepad…
- User
I would like to include in a VBA module, an event that will copy A1:C28 to a new notepad sheet, print the sheet and close notepad without saving
- Assistant
Here is a VBA code that you can use for copying range A1:C28 to a new Notepad, printing the sheet, and then closing Notepad without saving:
Sub CopyToNotepadAndPrint() ' Define the range to be copied Dim rng As Range Set rng = ThisWorkbook.Worksheets("Sheet1").Range("A1:C28") ' Copy the range to clipboard rng.Copy ' Open Notepad and paste the copied range Shell "notepad.exe", vbNormalFocus Application.Wait Now + TimeValue("0:00:01") ' Wait for Notepad to open SendKeys "^v" ' Print the Notepad file Application.Wait Now + TimeValue("0:00:01") ' Wait for the paste to complete SendKeys "^p" ' Close Notepad without saving Application.Wait Now + TimeValue("0:00:02") ' Wait for the print dialog to open SendKeys "%{F4}" End SubMake sure to replace "Sheet1" with the name of your actual worksheet where the data is located.
Please note that using
SendKeysis not always reliable and may depend on the system settings. Also, the timings (Application.Wait) may need to be adjusted based on the speed of your system.