Results 1 to 9 of 9

Thread: M$ code not working...

  1. #1

    Thread Starter
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Resolved 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.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: M$ code not working...

    In a module in my current document I pasted in the MS code and it worked?
    VB Code:
    1. 'From MS Help Code Example
    2. Sub AddCanvasShapes()
    3.     Dim shpCanvas As Shape
    4.     Dim shpCanvasShapes As CanvasShapes
    5.     Dim shpCnvItem As Shape
    6.  
    7.     'Adds a new canvas to the document
    8.     Set shpCanvas = ActiveDocument.Shapes _
    9.         .AddCanvas(Left:=100, Top:=75, _
    10.         Width:=50, Height:=75)
    11.     Set shpCanvasShapes = shpCanvas.CanvasItems
    12.  
    13.     'Adds shapes to the CanvasShapes collection
    14.     With shpCanvasShapes
    15.         .AddShape Type:=msoShapeRectangle, _
    16.             Left:=0, Top:=0, Width:=50, Height:=50
    17.         .AddShape Type:=msoShapeOval, _
    18.             Left:=5, Top:=5, Width:=40, Height:=40
    19.         .AddShape Type:=msoShapeIsoscelesTriangle, _
    20.             Left:=0, Top:=25, Width:=50, Height:=50
    21.     End With
    22. End Sub
    Attached Images 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    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.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: M$ code not working...

    VB Code:
    1. Sub NewCanvasPicture()
    2.     Dim shpCanvas As Shape
    3.  
    4.     'Add a drawing canvas to the active document
    5.     Set shpCanvas = ActiveDocument.Shapes _
    6.         .AddCanvas(Left:=100, Top:=75, _
    7.         Width:=200, Height:=300)
    8.  
    9.     'Add a graphic to the drawing canvas
    10.     shpCanvas.CanvasItems.AddPicture _
    11.         FileName:="C:\Program Files\Microsoft Office\" & _
    12.             "Office\Bitmaps\Styles\stone.bmp", _
    13.         LinkToFile:=False, SaveWithDocument:=True
    14. End Sub


    OK, how's about this? From the "Addpicture" part of Office Help. Feel free to substitute your own piccy.


    zaza

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: M$ code not working...

    I get an "Argument not optional".
    VB Code:
    1. Sub NewCanvasPicture()
    2.     Dim shpCanvas As Shape
    3.  
    4.     'Add a drawing canvas to the active document
    5.     Set shpCanvas = ActiveDocument.Shapes.AddCanvas(Left:=100, Top:=75, Width:=200, Height:=300)
    6.  
    7.     'Add a graphic to the drawing canvas
    8.     shpCanvas.CanvasItems.AddPicture FileName:="D:\Dog1.gif", LinkToFile:=False, SaveWithDocument:=True
    9. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  7. #7

    Thread Starter
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    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

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Sub NewCanvasPicture()
    2.     Dim shpCanvas As Shape
    3.  
    4.     'Add a drawing canvas to the active document
    5.     Set shpCanvas = ActiveDocument.Shapes.AddCanvas(Left:=100, Top:=75, Width:=200, Height:=300)
    6.  
    7.     'Add a graphic to the drawing canvas
    8.     shpCanvas.CanvasItems.AddPicture FileName:="D:\Dog1.gif", LinkToFile:=False, SaveWithDocument:=True, Left:=1, Top:=1, Width:=20, Height:=30
    9. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  9. #9

    Thread Starter
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    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
  •  



Click Here to Expand Forum to Full Width