|
-
Jun 18th, 2008, 02:08 PM
#1
Thread Starter
Member
[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.
-
Jun 18th, 2008, 06:20 PM
#2
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
-
Jun 18th, 2008, 10:25 PM
#3
Thread Starter
Member
Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?
-
Jun 18th, 2008, 10:30 PM
#4
Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?
 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.
-
Jun 19th, 2008, 07:11 AM
#5
Thread Starter
Member
Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?
Nothing happens, the page just stays blank.
-
Jun 19th, 2008, 07:22 AM
#6
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?
-
Jun 19th, 2008, 07:50 AM
#7
Hyperactive Member
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!
-
Jun 19th, 2008, 10:30 AM
#8
Thread Starter
Member
Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?
 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.
-
Jun 19th, 2008, 03:57 PM
#9
Fanatic Member
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?
-
Jun 19th, 2008, 05:14 PM
#10
Thread Starter
Member
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?
-
Jun 19th, 2008, 05:44 PM
#11
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.
-
Jun 25th, 2008, 11:51 AM
#12
Thread Starter
Member
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.
-
Jun 25th, 2008, 05:51 PM
#13
Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?
 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.
-
Jun 26th, 2008, 12:59 AM
#14
Thread Starter
Member
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!
-
Jun 26th, 2008, 01:06 AM
#15
Re: Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?
Please mark your thread as RESOLVED.
-
Jun 26th, 2008, 04:17 PM
#16
Thread Starter
Member
Re: [RESOLVED] Possible to create a VBA macro that draws a circle using the drawing toolbar in Word?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|