473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Help with slow running XL Automation Code

I have this code that takes ~3 Mins to run while automating an XL
Instance (XL 2003). There are 558 Rows and 15 Columns in rngSelection.
So it is adding Named ranges on 8,000+ Cells. Is this just as good as
it's going to get?

Imports Excel = Microsoft.Office.Interop.Excel
<<Snip>>
With XL
.Application.Calculation =
Excel.XlCalculation.xlCalculationManual
.Application.ScreenUpdating = False
<<Snip>>
Dim rngSelection As Excel.Range = CType(.Range("A1").CurrentRegion,
Excel.Range)
.Range("B3").Select()
For iRow = 2 To CShort(rngSelection.Rows.Count)
For iColumn = 2 To
CShort(rngSelection.Columns.Count)

.ActiveWorkbook.Names.Add(Name:="_" _
& Trim(Replace(CType(.ActiveCell.Value,
String), "-", "_")) & "_" _
& CType(.Range("O2").Offset(0, -
rngSelection.Columns.Count + iColumn + 1).Value, String) _
, RefersToR1C1:=.ActiveCell.Offset(0,
iColumn - 1))

Next iColumn
.ActiveCell.Offset(1, 0).Select()
Next iRow
<<Snip>>
Mar 11 '08 #1
5 1366
I'm sorry did you say you're making 8,000 named ranges?

-Aaron

On Mar 11, 2:14*pm, Bill Schanks <wscha...@gmail.comwrote:
I have this code that takes ~3 Mins to run while automating an XL
Instance (XL 2003). There are 558 Rows and 15 Columns in rngSelection.
So it is adding Named ranges on 8,000+ Cells. Is this just as good as
it's going to get?

Imports Excel = Microsoft.Office.Interop.Excel
<<Snip>>
With XL
* * *.Application.Calculation =
Excel.XlCalculation.xlCalculationManual
* * *.Application.ScreenUpdating = False
<<Snip>>
Dim rngSelection As Excel.Range = CType(.Range("A1").CurrentRegion,
Excel.Range)
* * * * * * * * .Range("B3").Select()
* * * * * * * * For iRow = 2 To CShort(rngSelection.Rows..Count)
* * * * * * * * * * For iColumn = 2 To
CShort(rngSelection.Columns.Count)

* * * * * * * * * * * * .ActiveWorkbook.Names.Add(Name:="_" _
* * * * * * * * * * * * * * & Trim(Replace(CType(.ActiveCell.Value,
String), "-", "_")) & "_" _
* * * * * * * * * * * * * * & CType(.Range("O2").Offset(0, -
rngSelection.Columns.Count + iColumn + 1).Value, String) _
* * * * * * * * * * * * * * , RefersToR1C1:=..ActiveCell.Offset(0,
iColumn - 1))

* * * * * * * * * * Next iColumn
* * * * * * * * * * .ActiveCell.Offset(1, 0).Select()
* * * * * * * * Next iRow
<<Snip>>
Mar 12 '08 #2
Yes ... It's a long story. I took over support of this process and the
end result is that are multiple spreadsheets that link to this
spreadsheet via a named range. It's not perfect and needs to be re-
written. With my current set of projects it's just going to happen any
time soon.

So for now, I just need to make the current process work.

On Mar 12, 11:21 am, "aaron.ke...@gmail.com" <aaron.ke...@gmail.com>
wrote:
I'm sorry did you say you're making 8,000 named ranges?

-Aaron

On Mar 11, 2:14 pm, Bill Schanks <wscha...@gmail.comwrote:
I have this code that takes ~3 Mins to run while automating an XL
Instance (XL 2003). There are 558 Rows and 15 Columns in rngSelection.
So it is adding Named ranges on 8,000+ Cells. Is this just as good as
it's going to get?
Imports Excel = Microsoft.Office.Interop.Excel
<<Snip>>
With XL
.Application.Calculation =
Excel.XlCalculation.xlCalculationManual
.Application.ScreenUpdating = False
<<Snip>>
Dim rngSelection As Excel.Range = CType(.Range("A1").CurrentRegion,
Excel.Range)
.Range("B3").Select()
For iRow = 2 To CShort(rngSelection.Rows.Count)
For iColumn = 2 To
CShort(rngSelection.Columns.Count)
.ActiveWorkbook.Names.Add(Name:="_" _
& Trim(Replace(CType(.ActiveCell.Value,
String), "-", "_")) & "_" _
& CType(.Range("O2").Offset(0, -
rngSelection.Columns.Count + iColumn + 1).Value, String) _
, RefersToR1C1:=.ActiveCell.Offset(0,
iColumn - 1))
Next iColumn
.ActiveCell.Offset(1, 0).Select()
Next iRow
<<Snip>>
Mar 12 '08 #3
Bill Schanks wrote:
I have this code that takes ~3 Mins to run while automating an XL
Instance (XL 2003). There are 558 Rows and 15 Columns in rngSelection.
So it is adding Named ranges on 8,000+ Cells. Is this just as good as
it's going to get?
That's 8,000 inter-process marshals and calls. It's going to stay slow.

Any chance you can set this up so the code runs as a macro within the Excel
workbook? It would go much faster there. Maybe You could even inject the macro
into the workbook, then call it.
Mar 13 '08 #4
<mynameh...@comcast.netwrote:
That's 8,000 inter-process marshals and calls. It's going to stay slow.

Any chance you can set this up so the code runs as a macro within the Excel
workbook? It would go much faster there. Maybe You could even inject the macro
into the workbook, then call it.
Actually that's were it is now, and I am pulling it out for other
reasons. But I can setup new code within the book and then call that
macro.Thanks.
Mar 13 '08 #5
That dropped the execution time to below 20s ... Thanks.
Mar 13 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chandra Mohan | last post by:
Hi, We need help on following things, 1. Inputs on creating comments on the columns & Tables of a SQL Database & generating the sql script of that. 2. Is it possible to call a .exe file in...
17
by: VM | last post by:
In my Windows app, I'm running a batch process that's composed of a FOR loop that'll run 15,000 times (datatable row count), copy cthe data of each row -3 fields- to a struct, and send the strct to...
16
by: Dean R. Henderson | last post by:
I have a project built for ASP.NET that recently started running really slow in debug mode (it takes about 10 seconds or more to step from one line of code to the next). This just started...
0
by: salad | last post by:
I'm on A97 and have Outlook 2003 on the computer. There's some generic code at Tony Toew's site and at MS and on the web that's very similar....but I can't make it work. I want to use late...
3
by: =?Utf-8?B?QmFkaXM=?= | last post by:
I'm doing a server side automation(I know it's bad but..) and its working fine locally and when accessing it from a remote machine using web browser is was giving me this error"Retrieving the COM...
7
by: Joey | last post by:
VS2005 asp.net 2.0 C# Developing with File System/Cassini instead of IIS (publish to IIS every so often) Hello guys, I have a web app where I am using static variables on many pages to...
0
by: Bullfrog | last post by:
My office application is really slow on Windows XP! First, some backgroud stuff. The MSAccess system that we use was developed while using Windows 2000, and Office 2000. At our new location,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.