<?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 Create new textstyle if one doesn't exist in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830305#M8328</link>
    <description>&lt;P&gt;I've learned how to create MText through VBA and utilize an existing Font Style, is it possible to have VBA check if a Font Style exists in the dwg? If so, it would continue the macro, if not then it would create a specified style. I can't find anything online about this other than directly changing an object's style upon creation, not about creating a style from scratch if&amp;nbsp;the style&amp;nbsp;doesn't exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 'CHECKED BY DATE
    Set MTextObj4 = ThisDrawing.ModelSpace.AddMText(corner4, widthN, text4)
        With MTextObj4
            .AttachmentPoint = acAttachmentPointMiddleLeft
            .InsertionPoint = corner4
            .StyleName = StyleName
            .Height = height1
        End With&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;... where StyleName = "PDF Search", the existing style.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jan 2017 15:19:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-01-25T15:19:36Z</dc:date>
    <item>
      <title>Create new textstyle if one doesn't exist</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830305#M8328</link>
      <description>&lt;P&gt;I've learned how to create MText through VBA and utilize an existing Font Style, is it possible to have VBA check if a Font Style exists in the dwg? If so, it would continue the macro, if not then it would create a specified style. I can't find anything online about this other than directly changing an object's style upon creation, not about creating a style from scratch if&amp;nbsp;the style&amp;nbsp;doesn't exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; 'CHECKED BY DATE
    Set MTextObj4 = ThisDrawing.ModelSpace.AddMText(corner4, widthN, text4)
        With MTextObj4
            .AttachmentPoint = acAttachmentPointMiddleLeft
            .InsertionPoint = corner4
            .StyleName = StyleName
            .Height = height1
        End With&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;... where StyleName = "PDF Search", the existing style.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 15:19:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830305#M8328</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-01-25T15:19:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create new textstyle if one doesn't exist</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830365#M8329</link>
      <description>&lt;P&gt;Here's a quick function. If it returns false, use ThisDrawing.Textsyles.Add()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Public Function HasTextStyle(StyleName As String) As Boolean
    Set HasTextStyle = False
    Dim name As String
    For Each name In ThisDrawing.TextStyles
        If name = StyleName Then HasTextStyle = True
    Next name
End Function&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jan 2017 15:37:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830365#M8329</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2017-01-25T15:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: Create new textstyle if one doesn't exist</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830421#M8330</link>
      <description>&lt;P&gt;Thanks for the swift reply, Ed! When I plug in this code, it keeps stating "Object required". Adding a Dim call for HasTextStyle As Object yields a duplication.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 15:59:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830421#M8330</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-01-25T15:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create new textstyle if one doesn't exist</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830434#M8331</link>
      <description>&lt;P&gt;You don't dim it. You're not creating an instance of the function, you just call it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If HasTextStyle("MyStyleName") = false then&lt;/P&gt;&lt;P&gt;&amp;nbsp; Dim myStyle As AcadTextStyle&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Set myStyle = ThisDrawing.TextStyles.Add("MyStyleName")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; myStyle. 'set some style properties here&lt;/P&gt;&lt;P&gt;End If&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 16:07:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830434#M8331</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2017-01-25T16:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Create new textstyle if one doesn't exist</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830740#M8332</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/14801"&gt;@Ed__Jobe&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Here's a quick function. If it returns false, use ThisDrawing.Textsyles.Add()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Function HasTextStyle(StyleName As String) As Boolean
    &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;Set HasTextStyle = False&lt;/STRONG&gt;&lt;/FONT&gt;
    Dim name As String
    For Each name In ThisDrawing.TextStyles
        If name = StyleName Then HasTextStyle = True
    Next name
End Function&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The red line code should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HasTextStyle = False '' That is, "Set" should be removed, because the function's return type is a value type, not an Object type.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 17:21:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830740#M8332</guid>
      <dc:creator>norman.yuan</dc:creator>
      <dc:date>2017-01-25T17:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create new textstyle if one doesn't exist</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830994#M8333</link>
      <description>&lt;P&gt;Oops, I thought I took that out. Thanks for catching it.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 18:56:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6830994#M8333</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2017-01-25T18:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create new textstyle if one doesn't exist</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6831033#M8334</link>
      <description>Cool. I got the code to accept into the form, how can I call them function from a button in the same form? I get "Argument not optional" with direct calls of HasTextStyle on the button.</description>
      <pubDate>Wed, 25 Jan 2017 19:09:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6831033#M8334</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-01-25T19:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create new textstyle if one doesn't exist</title>
      <link>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6831401#M8335</link>
      <description>&lt;P&gt;I've been toying with our template border and the VBA layouts, here is what I have:&lt;/P&gt;&lt;P&gt;(This is to tie into my first posting here on the forums of&amp;nbsp;&lt;A href="https://forums.autodesk.com/t5/visual-basic-customization/draw-multiple-lines/m-p/6828198#M99802" target="_blank"&gt;Draw multiple lines&lt;/A&gt;&amp;nbsp;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have written requires a pre-existing Text Style of "PDF Search" (hence why I started this thread of how to verify/create).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know what you think.&amp;nbsp; When "Accept&amp;amp;Close" is clicked, the Subs are run back to back, there is a separate form for another part of the title block available.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2017 21:21:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/create-new-textstyle-if-one-doesn-t-exist/m-p/6831401#M8335</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-01-25T21:21:29Z</dc:date>
    </item>
  </channel>
</rss>

