Results 1 to 16 of 16

Thread: [RESOLVED] Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    35

    Resolved [RESOLVED] Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Exactly what the title says. I'd like to make a macro that creates a circle or an oval, sized with a diameter of maybe 2 inches, and format it with a red border, no fill, and weight of 1.75.

    I tried making this macro like any other macro but it doesn't let me use the drawing toolbar. Is there a certain code for this that the macro creator doesn't let you use or is this simply impossible?

    I'm using Word 2003 btw.

    Or just a macro that would format the selected image with those properties if I had to draw the circle myself that's fine it's just a pain to have to format it every single time I make a circle.
    Last edited by x0rcist; Jun 18th, 2008 at 02:19 PM.

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Try this:
    Code:
    Sub DrawMyCircle()
        With ThisDocument.Shapes.AddShape(Type:=msoShapeOval, _
                                          Left:=InchesToPoints(1), _
                                          Top:=InchesToPoints(1), _
                                          Width:=InchesToPoints(2), _
                                          Height:=InchesToPoints(2))
            .Fill.Visible = msoFalse
            With .Line
                .Weight = 1.75
                .DashStyle = msoLineSolid
                .Style = msoLineSingle
                .Transparency = 0#
                .Visible = msoTrue
                .ForeColor.RGB = RGB(255, 0, 0)
                .BackColor.RGB = RGB(255, 255, 255)
            End With
        End With
    End Sub
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    35

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Nope, it didn't work

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Quote Originally Posted by x0rcist
    Nope, it didn't work
    What do you mean "it didn't work"?
    Does it do nothing or prompt any error?
    It works perfectly on my Word-2003.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    35

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Nothing happens, the page just stays blank.

  6. #6
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Can you tell how you use the code I posted?
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  7. #7
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    280

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Code:
    Private Sub CommandButton1_Click()
        DrawMyCircle
    End Sub
    
    Sub DrawMyCircle()
        With ThisDocument.Shapes.AddShape(Type:=msoShapeOval, _
                                          Left:=InchesToPoints(1), _
                                          Top:=InchesToPoints(1), _
                                          Width:=InchesToPoints(2), _
                                          Height:=InchesToPoints(2))
            .Fill.Visible = msoFalse
            With .Line
                .Weight = 1.75
                .DashStyle = msoLineSolid
                .Style = msoLineSingle
                .Transparency = 0#
                .Visible = msoTrue
                .ForeColor.RGB = RGB(255, 0, 0)
                .BackColor.RGB = RGB(255, 255, 255)
            End With
        End With
    End Sub
    Drew a red circle in Word 2000 for me when I pressed the button. Nice code, I will have to play with this some more.
    Slower than a crippled Vista
    More buggy than a fresh XP install
    Look! Down the road, some 50 miles behind the drunken snail.
    It's Ubuntu!

  8. #8

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    35

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Quote Originally Posted by anhn
    Can you tell how you use the code I posted?
    I just copy and pasted it into the VB Editor in MS Word underneath my other macros and then clicked it from the macro window.

  9. #9
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    577

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Worked on my end, too. You sure you don't have macros disabled, x0rcist?

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    35

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Yeah I've got plenty of other macros that work fine. I put security at very low as well. Is there anything else that might be messing it up?

  11. #11
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    The code use 5 constants from MS Office Library:
    Code:
        Const msoShapeOval = 9
        Const msoFalse = 0
        Const msoTrue = -1
        Const msoLineSolid = 1
        Const msoLineSingle = 1
    Add Option Explicit on very top of the module to see whether it complains about any variable not defined. If it does that is you don't have Microsoft Office library referenced.

    Otherwise you can define those constants as above.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  12. #12

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    35

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Wow, I just noticed that whenever I open a brand new blank document it creates the red circle instantly, but if I click the macro it doesn't make it.

    Oh, I and I think I accidentally mislead you guys. I'm trying to make this macro for use inside MS Word, not from a VB program to draw a circle in Word. I want to click this macro inside Word and have the circle drawn inside Word as well.

  13. #13
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Quote Originally Posted by x0rcist
    Wow, I just noticed that whenever I open a brand new blank document it creates the red circle instantly, but if I click the macro it doesn't make it.

    Oh, I and I think I accidentally mislead you guys. I'm trying to make this macro for use inside MS Word, not from a VB program to draw a circle in Word. I want to click this macro inside Word and have the circle drawn inside Word as well.
    For sure, the code I provided can only be run in Word VBA, that is not the code for VB program.

    Actually, the macro worked at the very first time you run it, but it drawn the Red circle into a wrong document:
    It drawn the circle to ThisDocument object of the file Normal.dot, not the active document currently open.
    Now every time you create a new document, Word will use the Normal.dot as a template to make it, and the document of the template already had the Red Circle embeded in it, that will be copied to any new document without running macros.

    It may be a mess for you now, you need to find and open the actual template file Normal.dot (under template file type) to remove the Red Circle.

    If you wish, you can leave the macro in Normal.dot to make it available to any document you open with reference to Normal template, but you have to change the keyword ThisDocument to ActiveDocument
    Last edited by anhn; Jun 25th, 2008 at 06:07 PM.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  14. #14

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    35

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Wonderful, I fixed my Normal.dot template back to... normal, and switched ThisDocument to ActiveDocument and now I can insert the circle whenever, wherever and it doesn't come up by default.

    Thanks for the help guys!

  15. #15
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Please mark your thread as RESOLVED.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  16. #16

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    35

    Re: [RESOLVED] Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?

    Gotcha

Posting Permissions

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



Click Here to Expand Forum to Full Width