Macro runs very slowly as .exe

Sheemie

New Member
Joined
Dec 3, 2005
Messages
2
Hi everyone. I'm using Excel 2000 with Xp Pro. I made a macro that opens another workbook and converts about 4000 rows of data using If statements and Select Case statements. The entire process takes about 16 seconds with screen updating disabled. If I make a .exe in VB 6.0 using the same code (with changes to open the workbook and excel), it takes about 6 minutes to complete the process. I'm opening Excel by:

Dim ExcelApp as Object
Dim FixThisCSV as Workbook
Set ExcelApp = CreateObject("Excel.Application")
Set FixThisCSV = ExcelApp.Workbooks.Open(MyFileNameHere)

It seems that the If..Then and Case parts are taking the longest. Any help would be appreciated.
Thanks
Kerry
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Welcome to MrExcel Board!

Does it have to be an .exe file? Executable files have a lot of machine overhead that you don't need, if you're going to be dealing with Excel workbooks anyway.

If it's a question of security, think about putting the code in an add-in, and protecting the project. There are several posts on the board that cover how to do that, but post back if you have problems or more questions on this topic.

Hope that helps!
 
Upvote 0
The problem with putting the code in an add in, is that the source code can be cracked in real-time.
 
Upvote 0
Thanks for the input, and thanks for the welcome Tazguy.
That's my hesitation about the add-in. It would seem that if I converted the code correctly to run in the exe, it would only take a little longer (two or three times as long would be ok). It seems likely that I've missed something going from the macro to the VB6, I just don't know what.
 
Upvote 0
Why are you late binding?

Dim ExcelApp as Object

Set a refernce and use

Dim ExcelApp as Excel.Application

Use strong typing. If you use late binding then the runtime has to check the reference hierarchy for every instance of every object. That will definitely slow thing way down. You should not notice any appreciable slowdown at all using VB as opposed to VBA.

If you will, post some or all of your code. You also have the option of creating a COM add-in.

Tom
 
Upvote 0

Forum statistics

Threads
1,214,665
Messages
6,120,804
Members
448,990
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top