<?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 Re: Add condition to use different template in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639178#M34532</link>
    <description>Hi Maperalia,&lt;BR /&gt;
&lt;BR /&gt;
The snip I posted was not meant to run as is.&lt;BR /&gt;
&lt;BR /&gt;
You will have to change the variable "lUpperLimit" (in the statement below)&lt;BR /&gt;
to match whatever variable you are using to hold the value from Excel.&lt;BR /&gt;
&lt;BR /&gt;
Select Case (lUpperLimit)' This variable should contain the 4000, 5000, 6000&lt;BR /&gt;
or 7000&lt;BR /&gt;
&lt;BR /&gt;
Also get rid of the "Dim lUpperLimit" statement&lt;BR /&gt;
&lt;BR /&gt;
Gary</description>
    <pubDate>Wed, 10 May 2006 20:01:21 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-05-10T20:01:21Z</dc:date>
    <item>
      <title>Add condition to use different template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639175#M34529</link>
      <description>The program I have below reads values from cells in excel and draw it in auto into the template1.&lt;BR /&gt;
I wonder if you can help me to add a condition if  the coordinates values (x,y) taken from excel are between:&lt;BR /&gt;
1.- 500 to 4000 use the template1&lt;BR /&gt;
2.- 500 to 5000 use template2&lt;BR /&gt;
3.- 500 to 6000 use template3&lt;BR /&gt;
4.- 500 to 7000 use tempalte4&lt;BR /&gt;
&lt;BR /&gt;
Can you please help me with this matter .&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
Maperalia&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'DRAW FROM EXCEL TO AUTOCAD&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
&lt;BR /&gt;
Public oAcadApp As AcadApplication&lt;BR /&gt;
Public oAcadDoc As AcadDocument&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Public Sub DrawInAutoCADFromExcel1()&lt;BR /&gt;
&lt;BR /&gt;
Dim i As Integer&lt;BR /&gt;
Dim lowerLoop As Integer: lowerLoop = 6&lt;BR /&gt;
Dim upperLoop As Integer: upperLoop = 100&lt;BR /&gt;
Dim minusValue As Integer&lt;BR /&gt;
Dim pointsColl As New Collection&lt;BR /&gt;
Dim acadApp As AcadApplication&lt;BR /&gt;
Dim pline As AcadLWPolyline&lt;BR /&gt;
Dim text As AcadText&lt;BR /&gt;
Dim textValue As String&lt;BR /&gt;
Dim textLocation(0 To 2) As Double&lt;BR /&gt;
Dim textHeight As Double: textHeight = 0.03&lt;BR /&gt;
Dim LWPoints() As Double&lt;BR /&gt;
&lt;BR /&gt;
'**********************************************************************&lt;BR /&gt;
'Insert Text&lt;BR /&gt;
Dim oTextEnt As AcadText&lt;BR /&gt;
Dim dInsertPoint(0 To 2) As Double&lt;BR /&gt;
Dim sTextString As String&lt;BR /&gt;
Dim dTextHeight As Double&lt;BR /&gt;
Dim lRowCount As Long&lt;BR /&gt;
&lt;BR /&gt;
dTextHeight = 0.06&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
AcadConnect 'Subroutine provided previously&lt;BR /&gt;
Set oAcadDoc = oAcadApp.ActiveDocument 'Connect to the open and active Drawing&lt;BR /&gt;
For lRowCount = 1 To ThisWorkbook.ActiveSheet.UsedRange.Rows.Count&lt;BR /&gt;
&lt;BR /&gt;
'Type coordinates location in the columns A &amp;amp; B for the text written in column D&lt;BR /&gt;
dInsertPoint(0) = CDbl(Val(ThisWorkbook.ActiveSheet.Cells(lRowCount, 1).Value))&lt;BR /&gt;
'dInsertPoint(0) = dInsertPoint(0) * 1000&lt;BR /&gt;
dInsertPoint(1) = CDbl(Val(ThisWorkbook.ActiveSheet.Cells(lRowCount, 2).Value))&lt;BR /&gt;
dInsertPoint(2) = 0#&lt;BR /&gt;
&lt;BR /&gt;
'Type the text value in the column D&lt;BR /&gt;
sTextString = ThisWorkbook.ActiveSheet.Cells(lRowCount, 4).Value&lt;BR /&gt;
&lt;BR /&gt;
Set oTextEnt = oAcadDoc.ModelSpace.AddText(sTextString, dInsertPoint, dTextHeight)&lt;BR /&gt;
&lt;BR /&gt;
oTextEnt.Layer = "0"&lt;BR /&gt;
oTextEnt.Alignment = acAlignmentMiddleLeft&lt;BR /&gt;
oTextEnt.TextAlignmentPoint = dInsertPoint&lt;BR /&gt;
oTextEnt.Color = acGreen&lt;BR /&gt;
oTextEnt.StyleName = "title"&lt;BR /&gt;
oTextEnt.Update&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Next lRowCount&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'***********************************************************************&lt;BR /&gt;
'Read Coordinates from Excel cells and Draw them in AutoCAD&lt;BR /&gt;
&lt;BR /&gt;
On Error GoTo stub_Error&lt;BR /&gt;
For i = lowerLoop To upperLoop&lt;BR /&gt;
   If Not Cells(i, 7) = "" And _&lt;BR /&gt;
   Not Cells(i, 8) = "" Then&lt;BR /&gt;
   pointsColl.Add Cells(i, 7)&lt;BR /&gt;
   pointsColl.Add Cells(i, 8)&lt;BR /&gt;
   Else: Exit For&lt;BR /&gt;
   End If&lt;BR /&gt;
Next i&lt;BR /&gt;
&lt;BR /&gt;
ReDim LWPoints(pointsColl.Count - 1) As Double&lt;BR /&gt;
&lt;BR /&gt;
For i = 0 To UBound(LWPoints)&lt;BR /&gt;
LWPoints(i) = pointsColl(i + 1)&lt;BR /&gt;
Next i&lt;BR /&gt;
&lt;BR /&gt;
If UBound(LWPoints) &amp;gt; 0 Then&lt;BR /&gt;
&lt;BR /&gt;
  With oAcadDoc.ModelSpace&lt;BR /&gt;
      '--------------------------------------------&lt;BR /&gt;
      'Draw the Polyline&lt;BR /&gt;
      Set pline = .AddLightWeightPolyline(LWPoints)&lt;BR /&gt;
      oAcadDoc.Regen acActiveViewport&lt;BR /&gt;
      pline.Color = acYellow&lt;BR /&gt;
      pline.Linetype = "Dot"&lt;BR /&gt;
      pline.LinetypeScale = 0.18&lt;BR /&gt;
      pline.Update&lt;BR /&gt;
      &lt;BR /&gt;
    If LWPoints(0) = LWPoints(UBound(LWPoints) - 1) And _&lt;BR /&gt;
      LWPoints(1) = LWPoints(UBound(LWPoints)) Then&lt;BR /&gt;
&lt;BR /&gt;
      minusValue = 2&lt;BR /&gt;
      Else: minusValue = 0&lt;BR /&gt;
      End If&lt;BR /&gt;
      '--------------------------------------------&lt;BR /&gt;
    &lt;BR /&gt;
&lt;BR /&gt;
      'Add Coordinates to the drawing&lt;BR /&gt;
       For i = 0 To (UBound(LWPoints) - minusValue) Step 2&lt;BR /&gt;
       textValue = LWPoints(i) &amp;amp; "," &amp;amp; LWPoints((i + 1))&lt;BR /&gt;
       textLocation(0) = LWPoints(i)&lt;BR /&gt;
       textLocation(1) = LWPoints((i + 1))&lt;BR /&gt;
       textLocation(2) = 0&lt;BR /&gt;
       Set text = .AddText(textValue, textLocation, textHeight)&lt;BR /&gt;
       text.Color = acYellow&lt;BR /&gt;
       Next i&lt;BR /&gt;
       &lt;BR /&gt;
        &lt;BR /&gt;
      &lt;BR /&gt;
'***********************************************************************&lt;BR /&gt;
       &lt;BR /&gt;
       &lt;BR /&gt;
       &lt;BR /&gt;
      oAcadDoc.Regen acActiveViewport&lt;BR /&gt;
  End With&lt;BR /&gt;
&lt;BR /&gt;
Else: Resume stub_Exit&lt;BR /&gt;
&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
stub_Exit:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
On Error GoTo 0&lt;BR /&gt;
&lt;BR /&gt;
Set pointsColl = Nothing&lt;BR /&gt;
Set acadApp = Nothing&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
&lt;BR /&gt;
stub_Error:&lt;BR /&gt;
Err.Clear&lt;BR /&gt;
Resume stub_Exit&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'Connect to AutoCAD&lt;BR /&gt;
Public Sub AcadConnect()&lt;BR /&gt;
If Err Then Err.Clear&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
Set oAcadApp = GetObject(, "AutoCAD.Application")&lt;BR /&gt;
If Err Then&lt;BR /&gt;
    Err.Clear&lt;BR /&gt;
    Set oAcadApp = CreateObject("AutoCAD.Application")&lt;BR /&gt;
        If Err Then&lt;BR /&gt;
            MsgBox "Could not connect to AutoCad"&lt;BR /&gt;
            Exit Sub&lt;BR /&gt;
        End If&lt;BR /&gt;
End If&lt;BR /&gt;
oAcadApp.Visible = True&lt;BR /&gt;
oAcadApp.WindowState = acMax&lt;BR /&gt;
oAcadApp.ZoomExtents&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
'Open Drawing&lt;BR /&gt;
Public Sub AcadOpenDoc(sFilename As String)&lt;BR /&gt;
Set oAcadDoc = oAcadApp.Documents.Open(sFilename)&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'Open an existen Template&lt;BR /&gt;
Public Sub Main()&lt;BR /&gt;
Dim sFilename As String&lt;BR /&gt;
AcadConnect&lt;BR /&gt;
sFilename = "S:\Templates\Template1.dwt"&lt;BR /&gt;
AcadOpenDoc sFilename&lt;BR /&gt;
DrawInAutoCADFromExcel1&lt;BR /&gt;
&lt;BR /&gt;
End Sub</description>
      <pubDate>Wed, 10 May 2006 00:10:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639175#M34529</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-10T00:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Add condition to use different template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639176#M34530</link>
      <description>"Select Case" seems to be a good choice for your conditions. Please see snip&lt;BR /&gt;
below&lt;BR /&gt;
&lt;BR /&gt;
Gary&lt;BR /&gt;
&lt;BR /&gt;
'Open an existen Template&lt;BR /&gt;
Public Sub Main()&lt;BR /&gt;
&lt;BR /&gt;
Dim sFilename As String&lt;BR /&gt;
&lt;BR /&gt;
AcadConnect&lt;BR /&gt;
&lt;BR /&gt;
Dim lUpperLimit As Long&lt;BR /&gt;
&lt;BR /&gt;
'Sub rountine entered with lUpperLimit set to 4000, 5000, 6000, or 7000&lt;BR /&gt;
&lt;BR /&gt;
Select Case (lUpperLimit)&lt;BR /&gt;
&lt;BR /&gt;
    Case 500 To 4000&lt;BR /&gt;
        sFilename = "S:\Templates\Template1.dwt"&lt;BR /&gt;
&lt;BR /&gt;
    Case 500 To 5000&lt;BR /&gt;
        sFilename = "S:\Templates\Template2.dwt"&lt;BR /&gt;
&lt;BR /&gt;
    Case 500 To 6000&lt;BR /&gt;
        sFilename = "S:\Templates\Template3.dwt"&lt;BR /&gt;
&lt;BR /&gt;
    Case 500 To 7000&lt;BR /&gt;
        sFilename = "S:\Templates\Template4.dwt"&lt;BR /&gt;
&lt;BR /&gt;
    Case Else&lt;BR /&gt;
        MsgBox "Error, using default template", vbExclamation + vbOKOnly,&lt;BR /&gt;
"Limits Error"&lt;BR /&gt;
        sFilename = "S:\Templates\Template1.dwt"&lt;BR /&gt;
End Select&lt;BR /&gt;
&lt;BR /&gt;
AcadOpenDoc sFilename&lt;BR /&gt;
DrawInAutoCADFromExcel1&lt;BR /&gt;
&lt;BR /&gt;
End Sub</description>
      <pubDate>Wed, 10 May 2006 13:19:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639176#M34530</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-10T13:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add condition to use different template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639177#M34531</link>
      <description>Gary;&lt;BR /&gt;
Thanks for your quick response.&lt;BR /&gt;
I ran the macro you gave me, however, I changed the coordinates values to see if is taking the different templates. However, it is not recognizing the coordinates values because it always open with the template1.&lt;BR /&gt;
&lt;BR /&gt;
How can I make it recognize so the macro will open the template according the coordinates values?.&lt;BR /&gt;
&lt;BR /&gt;
Can you help me please with this matter?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance.&lt;BR /&gt;
Maperalia</description>
      <pubDate>Wed, 10 May 2006 19:45:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639177#M34531</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-10T19:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Add condition to use different template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639178#M34532</link>
      <description>Hi Maperalia,&lt;BR /&gt;
&lt;BR /&gt;
The snip I posted was not meant to run as is.&lt;BR /&gt;
&lt;BR /&gt;
You will have to change the variable "lUpperLimit" (in the statement below)&lt;BR /&gt;
to match whatever variable you are using to hold the value from Excel.&lt;BR /&gt;
&lt;BR /&gt;
Select Case (lUpperLimit)' This variable should contain the 4000, 5000, 6000&lt;BR /&gt;
or 7000&lt;BR /&gt;
&lt;BR /&gt;
Also get rid of the "Dim lUpperLimit" statement&lt;BR /&gt;
&lt;BR /&gt;
Gary</description>
      <pubDate>Wed, 10 May 2006 20:01:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639178#M34532</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-10T20:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add condition to use different template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639179#M34533</link>
      <description>Gary;&lt;BR /&gt;
I sorry but I am little confuse. My knowledge in VBA is not as good to understand what you just explained me.&lt;BR /&gt;
&lt;BR /&gt;
My understanding is that I have to do as I wrote below. However, I still do not understand how this information will read the following statement which is the the information taken from the excel cells.:&lt;BR /&gt;
For i = lowerLoop To upperLoop&lt;BR /&gt;
If Not Cells(i, 7) = "" And _&lt;BR /&gt;
Not Cells(i, 8) = "" Then&lt;BR /&gt;
pointsColl.Add Cells(i, 7)&lt;BR /&gt;
pointsColl.Add Cells(i, 8)&lt;BR /&gt;
Else: Exit For&lt;BR /&gt;
End If&lt;BR /&gt;
Next i&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'Open an existen Template&lt;BR /&gt;
Public Sub Main()&lt;BR /&gt;
Dim sFilename As String&lt;BR /&gt;
AcadConnect&lt;BR /&gt;
'Sub rountine entered with lUpperLimit set to 4000, 5000, 6000, or 7000&lt;BR /&gt;
Select Case (4000,5000,6000,7000)&lt;BR /&gt;
Case 500 To 4000&lt;BR /&gt;
sFilename = "S:\Templates\Template1.dwt"&lt;BR /&gt;
&lt;BR /&gt;
Case 500 To 5000&lt;BR /&gt;
sFilename = "S:\Templates\Template2.dwt"&lt;BR /&gt;
&lt;BR /&gt;
Case 500 To 6000&lt;BR /&gt;
sFilename = "S:\Templates\Template3.dwt"&lt;BR /&gt;
&lt;BR /&gt;
Case 500 To 7000&lt;BR /&gt;
sFilename = "S:\Templates\Template4.dwt"&lt;BR /&gt;
&lt;BR /&gt;
Case Else&lt;BR /&gt;
MsgBox "Error, using default template", vbExclamation + vbOKOnly,&lt;BR /&gt;
"Limits Error"&lt;BR /&gt;
sFilename = "S:\Templates\Template1.dwt"&lt;BR /&gt;
End Select&lt;BR /&gt;
&lt;BR /&gt;
AcadOpenDoc sFilename&lt;BR /&gt;
DrawInAutoCADFromExcel1&lt;BR /&gt;
&lt;BR /&gt;
End Sub &lt;BR /&gt;
&lt;BR /&gt;
Kind regards.&lt;BR /&gt;
Maperalia</description>
      <pubDate>Thu, 11 May 2006 23:51:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639179#M34533</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-11T23:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Add condition to use different template</title>
      <link>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639180#M34534</link>
      <description>&amp;gt;&amp;gt;Select Case (4000,5000,6000,7000)&lt;BR /&gt;
The value to be tested by "Select Case" needs to be a variable. Hard coded&lt;BR /&gt;
values, as in the above, will give the same answer every time.&lt;BR /&gt;
&lt;BR /&gt;
pointsColl.Add Cells(i, 7)&lt;BR /&gt;
pointsColl.Add Cells(i, 8)&lt;BR /&gt;
&lt;BR /&gt;
The value(s) 4000 or 5000 or 6000 or 7000 that appear to be coming from your&lt;BR /&gt;
statements (above) need to be passed to the "Select Case" statement somehow.&lt;BR /&gt;
&lt;BR /&gt;
You could use a global variable to store whatever it is you are trying to&lt;BR /&gt;
test.&lt;BR /&gt;
&lt;BR /&gt;
MyPublicExcelMaxValue = Thisworkbook.ActiveSheet.Cells(i,8).Value' Or&lt;BR /&gt;
wherever you value comes from&lt;BR /&gt;
&lt;BR /&gt;
Then in the other sub it would be something like:&lt;BR /&gt;
&lt;BR /&gt;
Select Case (MyPublicExcelMaxValue)&lt;BR /&gt;
&lt;BR /&gt;
See VBA help for the "Select Case" statement. It may be cleaner / better to&lt;BR /&gt;
just put the "Select Case" in the same sub that returns the value you are&lt;BR /&gt;
trying to test. Then you could choose your template file name in that same&lt;BR /&gt;
sub without any extra confusion.&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
&lt;BR /&gt;
Gary</description>
      <pubDate>Fri, 12 May 2006 12:05:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/add-condition-to-use-different-template/m-p/1639180#M34534</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-05-12T12:05:11Z</dc:date>
    </item>
  </channel>
</rss>

