View Single Post
 
Old 09-11-2020, 05:10 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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

In terms of principles, if your Excel data is contained in a single sheet but you need to grab information from it right through your code then you should only grab it once and store that either in memory or write it to somewhere in the Word doc so that the Excel workbook connection can be closed again. You don't want to keep reconnecting or hold the connection open while other stuff goes on if you can avoid it.

Your code is amalgamating the tabular data from Excel into strings using commas "," as a delimiter which will then enable you to examine the string and work out which column supplied the substring. This will fail spectacularly if strings appear in the source data. For this reason, it is better to use a character as your delimiter that WILL NEVER appear in the source data. For this purpose I tend to use "|" but anything will do. The rows are then separated by carriage returns which should be OK as long as there are none in your Excel source.

Then finally your code ends with a disabled line which would have written the gathered data to a userform control. Without this, as soon as the code finishes, the information gathered is lost and you will need to revisit Excel to get it back again. You could alternatively write it to other places but there isn't code there for that.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote