I was wondering how I can change this VBA code so that the string it inserts is in Architectural format instead of the format its in example: 1-1/2" = 1'-0" is inserted as 1:8. My end goal would be to have a shortcut or a macro button set up so that after I change the scale on the current page and select the text I could quickly update the current pages scale reference included in my drawings. Thanks!
Sub InsertWorldScaleAsText() ' Get world scale Dim scaleFactor As Double Dim scaleText As String
scaleFactor = ActiveDocument.WorldScale scaleText = "1:" & Format(scaleFactor)
' Insert text into selected shape If Not ActiveShape Is Nothing Then If ActiveShape.Type = cdrTextShape Then ActiveShape.Text.Story = scaleText MsgBox "World scale inserted: " & vbCrLf & scaleText, vbInformation, "Scale Info" Else MsgBox "Please select a text shape.", vbExclamation End If Else MsgBox "No shape is selected.", vbExclamation End IfEnd Sub
I've been putting together a small collection of VBA macros under the name "Cedar Shakes" ( https://sourceforge.net/projects/cedar-shakes/ )
One of the modules I have is called "BadMath" and has a function to change decimals to vulgar fractions and vice-versa, as well as a ratio method.
If you use the "DecimalAsRatio" function you can feed the WorldScale into it and get a ratio back.
This hasn't been tested too much, but does seem to wrangle at least some of the basics.
Thanks Jeff - I'll take a look at it and see if I can find a workaround. I appreciate the link as well, I'll check them out.
Have you considered defining a list of different WorldScales that you might expect to encounter in your work?
If you came up with a list, then you could just use a Select Case statement that would use the WorldScale value to select the appropriate text string.
You could have a Case Else statement that would create the text directly from the value if you had fed it some worldscale for which you had not created a specific Case.
Hey Eskimo - thanks for your response. I was able to get it working, although some of the scales do not convert to the "standard" list of scales available in CorelDRAW. Ideally I would like it to follow this same nomenclature, maybe I will keep tweaking on the current conversions and see if I can get it figured out. Below are the standard scales that I work with on the daily.
The reason for the macro is many times I am working on a drawing package that may contain 30-40 pages each page having a specific scale set per page. I also stumbled on a thread from a while back in which you mentioned what my ideal solution for the scenario would be, but I couldn't locate any thing thus far.
I have also attached the current macro I am working with. I would be grateful for any suggestions you may have.
FYI - I use many of your macros currently in my workflow, thank you for all your efforts!
InsertWorldScale.zip
What I was thinking of was more brute force, essentially making a list of the scales with which you work, and your preferred text descriptions of them, e.g.:
Sub show_worldscale() MsgBox text_description_from_WorldScale(ActiveDocument.worldscale) End Sub Function text_description_from_WorldScale(dblWorldScale As Double) As String Select Case dblWorldScale Case 16 text_description_from_WorldScale = "3/4"" = 1'-0""" Case 24 text_description_from_WorldScale = "1/2"" = 1'-0""" Case 192 text_description_from_WorldScale = "1/16"" = 1'-0""" Case Else text_description_from_WorldScale = CStr(dblWorldScale) End Select End Function
Montana_1 said: I use many of your macros currently in my workflow
Hey, thank you for the kind words!
If you don't mind me asking - which ones do you find particularly useful?