![]() |
|
#2
|
||||
|
||||
|
You are only reading from Excel so you don't need it open once you read the info from it. Read the sheet in as an array (or just the 15th column of cells for efficiency) and then have your loop get the values from that array.
Code:
Sub Comments_AddResponsesToAll_6() ' 08/10/2020
' Loops through all comments and appends text from Excel to beginning of the comment.
Dim rngComment As Range, lngCommentNum As Long, arrExcelData As Variant
arrExcelData = GetExcelData 'get the excel data once and store in an array for reuse
For lngCommentNum = 1 To (ActiveDocument.Comments.Count)
Set rngComment = ActiveDocument.Comments(lngCommentNum).Range
rngComment.InsertBefore arrExcelData(lngCommentNum, 14) & vbCr
Next
End Sub
Function GetExcelData() As Variant
Dim myWB As Excel.Workbook
Dim objExcel As New Excel.Application
Set myWB = objExcel.Workbooks.Open("C:\Temp\TestFile.xlsx")
GetExcelData = myWB.sheets(1).UsedRange.Value
myWB.Close
Set myWB = Nothing
Set objExcel = Nothing
End Function
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Concurrent Calls in Excel | sbcccc | Excel | 1 | 08-15-2018 12:24 AM |
| Is there a way to search all workbooks for speciic function calls? | Jennifer Murphy | Excel Programming | 4 | 07-01-2018 03:55 AM |
| Rest api calls in excel | Santhosh_84 | Excel Programming | 0 | 06-24-2016 10:31 AM |
Need to improve speed of Excel macro that searches for whole word matches
|
Marrick13 | Excel Programming | 20 | 02-19-2016 09:54 AM |
how to speed up macro
|
AC PORTA VIA | Excel | 3 | 10-30-2015 08:58 PM |