<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to run faster autocad-excel in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434767#M16318</link>
    <description>I have done a lot of Autocad vba routines that interact with excel. I want to be able to make them run faster. I understood that is possible to create a database and to run my queries through this database from autocad.&lt;BR /&gt;
Can somebody help me with an example&lt;BR /&gt;
Thank you</description>
    <pubDate>Fri, 20 Feb 2009 18:55:07 GMT</pubDate>
    <dc:creator>dancalgary</dc:creator>
    <dc:date>2009-02-20T18:55:07Z</dc:date>
    <item>
      <title>How to run faster autocad-excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434767#M16318</link>
      <description>I have done a lot of Autocad vba routines that interact with excel. I want to be able to make them run faster. I understood that is possible to create a database and to run my queries through this database from autocad.&lt;BR /&gt;
Can somebody help me with an example&lt;BR /&gt;
Thank you</description>
      <pubDate>Fri, 20 Feb 2009 18:55:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434767#M16318</guid>
      <dc:creator>dancalgary</dc:creator>
      <dc:date>2009-02-20T18:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to run faster autocad-excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434768#M16319</link>
      <description>{code}routines that interact with excel. I want to be able to make them run faster.{code} &lt;BR /&gt;
I would go with VSTO and AutoCAD .NET. For database I (personally, there might be other better choices) would use SQL Server Express (Free version).  There are a lot of sample on the topic on the web.  Good luck.</description>
      <pubDate>Fri, 20 Feb 2009 20:57:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434768#M16319</guid>
      <dc:creator>HJohn1</dc:creator>
      <dc:date>2009-02-20T20:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to run faster autocad-excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434769#M16320</link>
      <description>My personal experience is to take a good, tough look at the code. Most of the times i see VB being (markedly) slower is because VB *lets* you write sloppy stuff.&lt;BR /&gt;
&lt;BR /&gt;
First places Id look:&lt;BR /&gt;
&lt;BR /&gt;
1) Excel: is your excel code macros that were recorded, with a few variables thrown in to replace the 'hard' vales put in while recording? Thats a no-no. Macro recorders try and emulate what a user would do using the keyboard/mouse. And thats usually no more efficient. Dont "select" cells, assign them to a range object. Turn off screen updates. Remember, your code is running like there  is NO screen visible; you are working with your eyes closed.&lt;BR /&gt;
&lt;BR /&gt;
2) Loops: Move everything you can out of the loop. I dont care what loop it is, if you are setting values that dont need to be set, it slows you right down.&lt;BR /&gt;
&lt;BR /&gt;
3) Variants: Toss em wherever possible, use strict typing of your variables and avoid conversions wherever possible.&lt;BR /&gt;
&lt;BR /&gt;
4) OLE: Early Binding. Its faster to develop this way, and runs a smite faster on running.&lt;BR /&gt;
&lt;BR /&gt;
5) Compiling: Its longer to develop, but faster to run, if you take your VBA and make it VB instead.&lt;BR /&gt;
&lt;BR /&gt;
6) Apparent speed: Splash screens werent invented 'cause  they look cool, they take the users mind off the fact that something else is loading. Check for data validity when the text box loses focus. Start Excel invisibly while the user is doing something else in Acad. Your app is probably sitting idle at the start, waiting for something to do... and then trying to do everything after the user clicks a button - get done, what can be done, up front. Its also a good way to check for errors and such before you get stuck in some long, slow loop.</description>
      <pubDate>Sat, 21 Feb 2009 10:59:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434769#M16320</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-02-21T10:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to run faster autocad-excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434770#M16321</link>
      <description>Hi rocheey,&lt;BR /&gt;
&lt;BR /&gt;
While most of the advise you gave is good, some items might be seen from &lt;BR /&gt;
a different viewpoint.&lt;BR /&gt;
&lt;BR /&gt;
"Most of the times i see VB being (markedly) slower is because VB *lets* &lt;BR /&gt;
you write sloppy stuff."&lt;BR /&gt;
&lt;BR /&gt;
So what is different from all other programming languages?  You can &lt;BR /&gt;
write sloppy code in any language.&lt;BR /&gt;
&lt;BR /&gt;
"5) Compiling: Its longer to develop, but faster to run, if you take &lt;BR /&gt;
your VBA and make it VB instead."&lt;BR /&gt;
&lt;BR /&gt;
Only if you compile it to a DLL then reference it and call it from the &lt;BR /&gt;
VBA program.  Because an EXE file runs "Out of Process" in the AutoCAD &lt;BR /&gt;
environment, it runs slower than it would as VBA code.&lt;BR /&gt;
&lt;BR /&gt;
"Check for data validity when the text box loses focus"&lt;BR /&gt;
&lt;BR /&gt;
While not unncessary, it's better to check the input as the user makes &lt;BR /&gt;
it and reject invalid input to a control before exiting the control. &lt;BR /&gt;
The user will never notice this happening, whereas a rejection on &lt;BR /&gt;
exiting the control always ends up being inconvenient to the user.&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Laurie Comerford&lt;BR /&gt;
&lt;BR /&gt;
rocheey wrote:&lt;BR /&gt;
&amp;gt; My personal experience is to take a good, tough look at the code. Most &lt;BR /&gt;
&amp;gt; of the times i see VB being (markedly) slower is because VB *lets* you &lt;BR /&gt;
&amp;gt; write sloppy stuff. First places Id look: 1) Excel: is your excel code &lt;BR /&gt;
&amp;gt; macros that were recorded, with a few variables thrown in to replace the &lt;BR /&gt;
&amp;gt; 'hard' vales put in while recording? Thats a no-no. Macro recorders try &lt;BR /&gt;
&amp;gt; and emulate what a user would do using the keyboard/mouse. And thats &lt;BR /&gt;
&amp;gt; usually no more efficient. Dont "select" cells, assign them to a range &lt;BR /&gt;
&amp;gt; object. Turn off screen updates. Remember, your code is running like &lt;BR /&gt;
&amp;gt; there is NO screen visible; you are working with your eyes closed. 2) &lt;BR /&gt;
&amp;gt; Loops: Move everything you can out of the loop. I dont care what loop it &lt;BR /&gt;
&amp;gt; is, if you are setting values that dont need to be set, it slows you &lt;BR /&gt;
&amp;gt; right down. 3) Variants: Toss em wherever possible, use strict typing of &lt;BR /&gt;
&amp;gt; your variables and avoid conversions wherever possible. 4) OLE: Early &lt;BR /&gt;
&amp;gt; Binding. Its faster to develop this way, and runs a smite faster on &lt;BR /&gt;
&amp;gt; running. 5) Compiling: Its longer to develop, but faster to run, if you &lt;BR /&gt;
&amp;gt; take your VBA and make it VB instead. 6) Apparent speed: Splash screens &lt;BR /&gt;
&amp;gt; werent invented 'cause they look cool, they take the users mind off the &lt;BR /&gt;
&amp;gt; fact that something else is loading. Check for data validity when the &lt;BR /&gt;
&amp;gt; text box loses focus. Start Excel invisibly while the user is doing &lt;BR /&gt;
&amp;gt; something else in Acad. Your app is probably sitting idle at the start, &lt;BR /&gt;
&amp;gt; waiting for something to do... and then trying to do everything after &lt;BR /&gt;
&amp;gt; the user clicks a button - get done, what can be done, up front. Its &lt;BR /&gt;
&amp;gt; also a good way to check for errors and such before you get stuck in &lt;BR /&gt;
&amp;gt; some long, slow loop.</description>
      <pubDate>Sat, 21 Feb 2009 20:21:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434770#M16321</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-02-21T20:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to run faster autocad-excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434771#M16322</link>
      <description>I have a few quick questions about Excel and running it in the background and what not.&lt;BR /&gt;
&lt;BR /&gt;
Here is my code it is the first attempt ot success at calling Excel from Autocad &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Private Sub UserForm_Initialize()&lt;BR /&gt;
    &lt;BR /&gt;
    'Read data in from EXCEL sheet&lt;BR /&gt;
&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
Dim ExcelApp As Excel.Application&lt;BR /&gt;
Dim tmp As String&lt;BR /&gt;
Dim i As Integer&lt;BR /&gt;
Dim Workbook As Excel.Workbook&lt;BR /&gt;
Dim WorkSheet As Excel.WorkSheet&lt;BR /&gt;
&lt;BR /&gt;
Set ExcelApp = GetObject(, "Excel.Application")&lt;BR /&gt;
&lt;BR /&gt;
    If Err Then&lt;BR /&gt;
        Err.Clear&lt;BR /&gt;
        Set ExcelApp = CreateObject("Excel.Application")&lt;BR /&gt;
        If Err Then&lt;BR /&gt;
            MsgBox "Cannot start Excel", vbCritical, "Error Starting Excel"&lt;BR /&gt;
            Unload Me&lt;BR /&gt;
        End If&lt;BR /&gt;
    End If&lt;BR /&gt;
ExcelApp.Visible = True&lt;BR /&gt;
&lt;BR /&gt;
Set Workbook = ExcelApp.Workbooks.Open("C:\clients.xls")&lt;BR /&gt;
Set WorkSheet = ExcelApp.Worksheets(1)&lt;BR /&gt;
&lt;BR /&gt;
ExcelApp.Parent.Windows(1).Visible = False&lt;BR /&gt;
&lt;BR /&gt;
With dataListBox&lt;BR /&gt;
    i = 1&lt;BR /&gt;
    tmp = WorkSheet.Cells(i, 1).Value&lt;BR /&gt;
    Do While tmp &amp;lt;&amp;gt; ""&lt;BR /&gt;
        .AddItem WorkSheet.Cells(i, 1).Value&lt;BR /&gt;
        i = i + 1&lt;BR /&gt;
        tmp = WorkSheet.Cells(i, 1).Value&lt;BR /&gt;
    Loop&lt;BR /&gt;
End With&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
How might I be able to make that code better?&lt;BR /&gt;
Here is the things I would like to change about it from my point of view.&lt;BR /&gt;
1. I dont want to screw around with any documents that Excel may have open, such as saving them or closing Excel or anything like that, I do need to close out of the work book but I thought I would put that under the Cancel button action or after I am done doing my work with excel.&lt;BR /&gt;
2. Autocad/Macro/Dialog box to keep focus and not Excel.&lt;BR /&gt;
&lt;BR /&gt;
Hope to hear back from you guys and I love reading this form it helps out a lot.&lt;BR /&gt;
&lt;BR /&gt;
--Zac</description>
      <pubDate>Thu, 26 Feb 2009 00:37:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/how-to-run-faster-autocad-excel/m-p/2434771#M16322</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-02-26T00:37:25Z</dc:date>
    </item>
  </channel>
</rss>

