Oct 9th, 2005, 01:21 PM
#1
M$ code not working...
Hm, most confusing. If I go to the CanvasShapes bit of the Office XP help (do a search in VBA help, Word) and get the code therein for adding a new canvas item followed by some shapes, then I find it doesn't work in my current project.
However, if I start a new document, bung a button in and paste the code in there it does.
What is going on?
zaza
Last edited by zaza; Oct 10th, 2005 at 02:51 PM .
Oct 9th, 2005, 01:24 PM
#2
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
Attached Images
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Oct 10th, 2005, 01:32 PM
#3
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.
Oct 10th, 2005, 01:49 PM
#4
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?
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Oct 10th, 2005, 02:21 PM
#5
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
Oct 10th, 2005, 02:40 PM
#6
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
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Oct 10th, 2005, 02:44 PM
#7
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
Oct 10th, 2005, 02:59 PM
#8
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
VB/Office Guru™ (AKA: Gangsta Yoda ™ ® )
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Oct 10th, 2005, 03:03 PM
#9
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...?
Cheers Rob.
zaza
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