Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to put a pic in a drawing canvas?

Status
Not open for further replies.

killercrossover

Programmer
Apr 10, 2008
8
US
here the problem i get this error "Run-time error'449': Argument not optional" on line in red
***************code****************************************
Sub NewCanvasPicture()
Dim shpCanvas As Shape
Dim pic As String
pic = "D:\Documents and_ Settings\kspencer\Desktop\Sample.jpg"
'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:=pic, LinkToFile:=False, SaveWithDocument:=True
End Sub
**********************code*********************************
Selection.InlineShapes.AddPicture Filename:=pic, LinkToFile:=False, SaveWithDocument:=True
if i use this line of code in place of the one in red it put the pic on the word doc but not in the drawing canvas. im really trying to is insert a pic on a word to specific location on a form that i got a marco make for me.
 
You obviously got the starting code from Help. And, alas, indeed, if you use the actual code in Help (but substitute a legal path to your own image file), it will fail with the error mentioned. In other words, even the Help code will fail.

AddPicture is a function. In the Object Browser, it looks like the parameters Left, Top, Width, Height are Optional. The Help code shows as if they are optional.

However...you do get that error, and it means exactly what it says. Argument not optional.

It is worse than you think, and I do not fully understand it. Say the image file is "c:\cells.jpg" (for brevity sake).
Code:
 shpCanvas.CanvasItems.AddPicture _
   FileName:="C:\cells.jpg", LinkToFile:=False, _
   SaveWithDocument:=True, Left:=0, Top:=0
will fail as subscript out-of-range. But.......
Code:
 shpCanvas.CanvasItems.AddPicture _
   FileName:="C:\cells.jpg", LinkToFile:=False, _
   SaveWithDocument:=True, Left:=0, Top:=0, _
   Width:=70
will NOT fail.

Go figure. How can an existing passed value be "out-of-range"...and NOT be out-of-range when you add a [/b]different[/b] parameter....and passed value (previously out-of-range) is exactly the same?

I dunno.

In any case, try playing with passing values for the picture.


faq219-2884

Gerry
My paintings and sculpture
 
Thank You fumei it work by the i just use a geniric example that was really not my code but that it work for my code. it was easy thing do to make myself clear. Thanks you again
[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top