Consulting

Results 1 to 17 of 17

Thread: Solved: Creating "At and Angle" Symbol in VBA

  1. #1

    Solved: Creating "At and Angle" Symbol in VBA

    Hey guys, I need for my VBA macro to create a string that looks like this:

    outputString = "12 /_ 90 o"

    (Which reads twelve at an angle of 90 degrees in polar coordinates, incase what I typed didn't make sense)

    Except that i need the /_ to be replaced with the actual angle symbol and the o to be replaced with the superscripted degree sign.

    I did a good bit of googling and I figured out how I can do this in a userform caption using the "Symbol" font but I need to do this in my output string now.

    Any ideas?

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    For the degree sign, you should be able to use Chr(186)

    Not sure on the angle sign, maybe look thru the various symbol fonts and see if anything is acceptable?

    I tried this exceptionally cheesy ccode just to list what else might return, but didn't see anything close...
    Sub ListChar()
    Dim i As Long, j As Long
    Dim ary(1 To 50000, 1 To 2)
        For i = -32768 To 65535
            If Not Asc(ChrW(i)) = 63 Then
                j = j + 1
                ary(j, 1) = ChrW(i)
                ary(j, 2) = i
            End If
        Next
        
        [A2].Resize(50000, 2).Value = ary
        
    Beep
    End Sub
    Mark

  3. #3
    Thanks Mark.

    I just went through the list and I figured out that 272 produces Đ, which would actually be the angle symbol if font were set to 'Symbol'. I'm not sure if that helps me or not though.

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If you have GDT font try
    [VBA]
    Sub Angle()
    Data = Split(InputBox("Enter Number/Angle"), "/")
    ActiveCell = Data(0) & Chr(130) & Data(1) & Chr(176)
    With ActiveCell.Characters(Start:=Len(Data(0)) + 1, Length:=1).Font
    .Name = "GDT"
    End With
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Thanks MD, that worked perfectly in ActiveCell.

    I tried to modify it so that it would work in a string like this:

    txtBox.Value = "12 /_ 90 degrees"

    But I couldn't figure that out. Can I set the font for part of textBox control like you did with ActiveCell?

    Thanks again.

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You can't use more than one format in a textbox, so if GDT has no numbers, you would need to find another font which has numbers and where the angle symbol has a code value less than 255.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Use Arial Unicode

    [vba]
    Private Sub UserForm_Initialize()
    With Me.TextBox1
    .Font.Name = "@Arial Unicode MS"
    .Font.Size = "10"
    .Text = "12" & ChrW(8736) & "90" & ChrW(176)
    End With
    End Sub
    [/vba]


    Paul
    Last edited by Paul_Hossler; 03-18-2010 at 07:02 AM. Reason: Trying to add a picture -- didn't work - figured it out

  8. #8
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks Paul,
    I've never used ChrW, so couldn't see how to code these extended characters.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location

  10. #10
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  11. #11
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Gack! I never thought to try different fonts with them. Thanks for the nice info

  12. #12
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Lucas --

    Nice summary that shows the standard glyphs, but I didn't see how to select a font or view the Private Use Area (E000). Bablemap is more complicated, but the PUA varies between fonts so that's what I was looking for

    For example, in Adobe Garamond Pro Italic, E000 is a Swash-A.

    I need that kind of help when I'm looking for something


    Paul

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Paul, I downloaded it and it's pretty nice. We use it for musical symbols a lot. ♬

    The interface at the webpage I linked to only gives decimal. It's in grid format so you have to read from the left side and the column to get the numbers. The program you linked to will give you decimal or hex. Pretty handy.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  14. #14

    Thumbs up Resolved :D

    Thanks for all the great helps guys.

  15. #15
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Sam, please mark your thread solved using the thread tools at the top of the page.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  16. #16
    Quote Originally Posted by lucas
    Sam, please mark your thread solved using the thread tools at the top of the page.
    Done.

    Do we have any kind of rep or feedback system on this forum? I looked around but couldn't find anything.

  17. #17
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    You can rate the thread just to the right of thread tools.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •