The following VBA works very well but I would like a change. I want the values of column…
- User
The following VBA works very well but I would like a change.
I want the values of column I and column J copied then joined together with a space between and then pasted into Notepad.
Sub HistoryToNotepad() Dim sourceWorkbook As Workbook Dim destinationWorkbook As Workbook Dim sourceWorksheet As Worksheet Dim destinationWorksheet As Worksheet Dim path As String, fileName As String Dim lastRow As Long Dim i As Long path = "G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS" fileName = "Service Providers History.xlsx" Set sourceWorkbook = ThisWorkbook Set destinationWorkbook = Workbooks.Open(path & fileName) Dim activeSheetName As String activeSheetName = sourceWorkbook.ActiveSheet.Name Set sourceWorksheet = sourceWorkbook.ActiveSheet Set destinationWorksheet = destinationWorkbook.Sheets(activeSheetName) lastRow = destinationWorksheet.Cells(destinationWorksheet.Rows.Count, "J").End(xlUp).Row Shell "notepad.exe", vbNormalFocus Application.Wait Now + TimeValue("00:00:01") For i = 5 To lastRow SendKeys destinationWorksheet.Range("J" & i).Value SendKeys vbCrLf Next i SendKeys "^{HOME}" destinationWorkbook.Close False Set destinationWorksheet = Nothing Set destinationWorkbook = Nothing Set sourceWorksheet = Nothing Set sourceWorkbook = Nothing End Sub
- Assistant
Sub HistoryToNotepad() Dim sourceWorkbook As Workbook Dim destinationWorkbook As Workbook Dim sourceWorksheet As Worksheet Dim destinationWorksheet As Worksheet Dim path As String, fileName As String Dim lastRow As Long Dim i As Long Dim textToPaste As String
path = "G:\Shared drives\Swan School Site Premises\PREMISES MANAGEMENT\SERVICE PROVIDERS\" fileName = "Service Providers History.xlsx" Set sourceWorkbook = ThisWorkbook Set destinationWorkbook = Workbooks.Open(path & fileName) Dim activeSheetName As String activeSheetName = sourceWorkbook.ActiveSheet.Name Set sourceWorksheet = sourceWorkbook.ActiveSheet Set destinationWorksheet = destinationWorkbook.Sheets(activeSheetName) lastRow = destinationWorksheet.Cells(destinationWorksheet.Rows.Count, "J").End(xlUp).Row For i = 5 To lastRow textToPaste = destinationWorksheet.Range("I" & i).Value & " " & destinationWorksheet.Range("J" & i).Value Open "C:\Temp\NotepadOutput.txt" For Append As #1 Print #1, textToPaste Close #1 Next i Shell "notepad.exe C:\Temp\NotepadOutput.txt", vbNormalFocus destinationWorkbook.Close False Set destinationWorksheet = Nothing Set destinationWorkbook = Nothing Set sourceWorksheet = Nothing Set sourceWorkbook = Nothing
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.