Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 08-10-2020, 09:54 PM
Guessed's Avatar
Guessed Guessed is offline Speed up macro that calls Excel-based function Windows 10 Speed up macro that calls Excel-based function Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
 



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
Speed up macro that calls Excel-based function Need to improve speed of Excel macro that searches for whole word matches Marrick13 Excel Programming 20 02-19-2016 09:54 AM
Speed up macro that calls Excel-based function how to speed up macro AC PORTA VIA Excel 3 10-30-2015 08:58 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft