Hi everyone,
I'm new to VBA and I'm facing an issue with a macro that involves copying text from a Microsoft Word document based on data from an Excel file. I would appreciate your help in resolving this problem.
I want the macro to do the following:
1. Browse the specified Excel sheet
2. Find the text according to that specified Excel sheet
3. Copy them accordingly to the clipboard
I've attached the Excel file (which is a list of names) here.
LIST.xlsx
Here's the code I have so far. But it cannot work:
Sub CopyTextToClipboard() Dim xlApp As Object Dim xlWB As Object Dim xlWS As Object Dim rng As Range Set xlApp = CreateObject("Excel.Application") Set xlWB = xlApp.Workbooks.Open("C:\Users\Desktop\List.xlsx") Set xlWS = xlWB.Worksheets("LIST") Set rng = xlWS.Range("A2:A126") rng.copy xlWB.Close False xlApp.Quit Set rng = Nothing Set xlWS = Nothing Set xlWB = Nothing Set xlApp = Nothing End Sub
I would be grateful for any guidance or suggestions to improve this code and make it work as intended. Thank you in advance for your assistance.