1 Attachment(s)
Re: M$ code not working...
In a module in my current document I pasted in the MS code and it worked?
VB Code:
'From MS Help Code Example
Sub AddCanvasShapes()
Dim shpCanvas As Shape
Dim shpCanvasShapes As CanvasShapes
Dim shpCnvItem As Shape
'Adds a new canvas to the document
Set shpCanvas = ActiveDocument.Shapes _
.AddCanvas(Left:=100, Top:=75, _
Width:=50, Height:=75)
Set shpCanvasShapes = shpCanvas.CanvasItems
'Adds shapes to the CanvasShapes collection
With shpCanvasShapes
.AddShape Type:=msoShapeRectangle, _
Left:=0, Top:=0, Width:=50, Height:=50
.AddShape Type:=msoShapeOval, _
Left:=5, Top:=5, Width:=40, Height:=40
.AddShape Type:=msoShapeIsoscelesTriangle, _
Left:=0, Top:=25, Width:=50, Height:=50
End With
End Sub
Re: M$ code not working...
Indeed. And I can get it to work in a new document. But in the one I'm developing in it doesn't work, mostly. And sometimes it'll work but lose the border, so effectively it's invisible.
Mmm, strange.
Re: M$ code not working...
And I suppose re-creating the document will be too much work in case the doc may be partially damaged or ???
Latest 2003 service pack 2 installed and Office Update?
Re: M$ code not working...
VB Code:
Sub NewCanvasPicture()
Dim shpCanvas As Shape
'Add a drawing canvas to the active document
Set shpCanvas = ActiveDocument.Shapes _
.AddCanvas(Left:=100, Top:=75, _
Width:=200, Height:=300)
'Add a graphic to the drawing canvas
shpCanvas.CanvasItems.AddPicture _
FileName:="C:\Program Files\Microsoft Office\" & _
"Office\Bitmaps\Styles\stone.bmp", _
LinkToFile:=False, SaveWithDocument:=True
End Sub
OK, how's about this? From the "Addpicture" part of Office Help. Feel free to substitute your own piccy.
zaza
Re: M$ code not working...
I get an "Argument not optional".
VB Code:
Sub NewCanvasPicture()
Dim shpCanvas As Shape
'Add a drawing canvas to the active document
Set shpCanvas = ActiveDocument.Shapes.AddCanvas(Left:=100, Top:=75, Width:=200, Height:=300)
'Add a graphic to the drawing canvas
shpCanvas.CanvasItems.AddPicture FileName:="D:\Dog1.gif", LinkToFile:=False, SaveWithDocument:=True
End Sub
Re: M$ code not working...
As do I. I think I have tracked it down, though. It appears that the Left and Top are not, in fact, optional, and that you can't set both linktofile and Savewithdocument to be false. They both also have to be there, despite the fact that Help suggests that they are optional.
Grrrr [wrestles with bone]
zaza
Re: M$ code not working...
Solved it! Seems that the size of the picture must be in a different unit so when you specify the same size as the canvas its is invalid. Also, the left and top can not be outside the canvas area.
This works!
VB Code:
Sub NewCanvasPicture()
Dim shpCanvas As Shape
'Add a drawing canvas to the active document
Set shpCanvas = ActiveDocument.Shapes.AddCanvas(Left:=100, Top:=75, Width:=200, Height:=300)
'Add a graphic to the drawing canvas
shpCanvas.CanvasItems.AddPicture FileName:="D:\Dog1.gif", LinkToFile:=False, SaveWithDocument:=True, Left:=1, Top:=1, Width:=20, Height:=30
End Sub
Re: M$ code not working...
Aha! You can then resize it by Setting this to some variable, then changing the width and height. The canvas then sizes automatically.
Hurrah!
Care to look at my other problems now...? :D
Cheers Rob.
zaza