Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2016, 03:50 AM
Daniel Antone Daniel Antone is offline Programmatically make text box borders invisible Windows 10 Programmatically make text box borders invisible Office 2013
Novice
Programmatically make text box borders invisible
 
Join Date: Dec 2016
Location: Sydney Australia
Posts: 6
Daniel Antone is on a distinguished road
Default Programmatically make text box borders invisible

I am finding this is a real challenge.
This code supposes to set some properties of a text box. But Word sticks to the manually set defaults for auto shapes even if you try to change the defaults programmatically by using the property "SetShapesDefaultProperties"


Code:
  With Selection.ShapeRange(1)
    With .TextFrame
      .MarginLeft = 0
      .MarginRight = 0
      .MarginTop = 0
      .MarginBottom = 0
    End With
    .LockAnchor = False
    .WrapFormat.Type = wdWrapNone
    .Fill.Visible = msoFalse
    .Line.Visible = msoFalse
  End With
Any suggestions will be greatly appreciated.

Last edited by macropod; 01-01-2017 at 04:36 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 12-30-2016, 06:21 AM
macropod's Avatar
macropod macropod is offline Programmatically make text box borders invisible Windows 7 64bit Programmatically make text box borders invisible Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You code works fine for me as-is. It can only affect a selected shape, not Word's defaults. However, if you insert:
.SetShapesDefaultProperties
after:
.Line.Visible = msoFalse
Your current configuration becomes the default for all autoshapes added to the current document (e.g. they get inserted with no border & 0-width margins).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-01-2017, 04:14 PM
Daniel Antone Daniel Antone is offline Programmatically make text box borders invisible Windows 10 Programmatically make text box borders invisible Office 2013
Novice
Programmatically make text box borders invisible
 
Join Date: Dec 2016
Location: Sydney Australia
Posts: 6
Daniel Antone is on a distinguished road
Smile Formatting objects inside a canvas

Thanks Paul for your prompt reply, and happy new year
Yes, the code seems correct, especially it does not return an error message but, after running, it does not change the formats specified.
However, I was lucky this time, I found a solution. I used CanvasShapes and CanvasItems collections with a variable to refer to the textboxes then apply the formats. It worked. It seems the selection object is no good here.
Just in case if anybody needs this remark, it wasted many hours of my time, here is the correct code
Code:
  Dim shpCanvas As Shape 
  Dim shpCanvasShapes As CanvasShapes  
  
  'use to refer to each textbox inside the canvas
  Dim shpCanvasTB As Shape  

  Set shpCanvas = ActiveDocument.Shapes("MainCanvas")
  Set shpCanvasShapes = shpGridCanvas.CanvasItems
  
  For Each shpCanvasTB In shpCanvasShapes
    If shpCanvasTB.Type = msoTextBox Then
      
      With shpCanvasTB
        .Fill.Visible = msoFalse
        .Line.Visible = msoFalse
        With .TextFrame
          .MarginLeft = 0
          .MarginRight = 0
          .MarginTop = 0
          .MarginBottom = 0
        End With
        
        .Select
        With Selection
          .Font.Size = 12
          .ParagraphFormat.Alignment = wdAlignParagraphCenter
          .Font.Italic = True
        End With
        
      End With
      
    End If
    
  Next shpGridCanvasTB
Thanks again

Last edited by macropod; 01-01-2017 at 04:35 PM. Reason: Added code tags
Reply With Quote
  #4  
Old 01-01-2017, 04:43 PM
macropod's Avatar
macropod macropod is offline Programmatically make text box borders invisible Windows 7 64bit Programmatically make text box borders invisible Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As I said, though, the code you originally posted worked fine in my testing (i.e. it does change the formats specified) for an existing shape and, with the addition of .SetShapesDefaultProperties, becomes the default for the current document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 01-01-2017, 05:21 PM
Daniel Antone Daniel Antone is offline Programmatically make text box borders invisible Windows 10 Programmatically make text box borders invisible Office 2013
Novice
Programmatically make text box borders invisible
 
Join Date: Dec 2016
Location: Sydney Australia
Posts: 6
Daniel Antone is on a distinguished road
Default

Yes, of course, I understand your testing passed the code, thanks for doing that.
I do not know why it did not work in my environment at more than one machine.
Thanks for your time and replies.
Reply With Quote
  #6  
Old 01-01-2017, 06:10 PM
macropod's Avatar
macropod macropod is offline Programmatically make text box borders invisible Windows 7 64bit Programmatically make text box borders invisible Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Have you tried repairing the Office installation (via Windows Control Panel > Programs > Programs & Features > Microsoft Office (version) > Change > Repair)?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 01-01-2017, 07:47 PM
Daniel Antone Daniel Antone is offline Programmatically make text box borders invisible Windows 10 Programmatically make text box borders invisible Office 2013
Novice
Programmatically make text box borders invisible
 
Join Date: Dec 2016
Location: Sydney Australia
Posts: 6
Daniel Antone is on a distinguished road
Default

Oh, no I have not. I will try and let you know, thanks for telling me.
Reply With Quote
  #8  
Old 01-02-2017, 10:54 PM
Daniel Antone Daniel Antone is offline Programmatically make text box borders invisible Windows 10 Programmatically make text box borders invisible Office 2013
Novice
Programmatically make text box borders invisible
 
Join Date: Dec 2016
Location: Sydney Australia
Posts: 6
Daniel Antone is on a distinguished road
Default

Hi Paul
I ran an office online repair, i.e. reinstallation of office
then I have tried change the format of a textbox accessing it with the selection object.
It did not work, no change to formating took place.
Reply With Quote
  #9  
Old 10-23-2019, 05:57 PM
piecevcake piecevcake is offline Programmatically make text box borders invisible Windows 8 Programmatically make text box borders invisible Office 2007
Novice
 
Join Date: Oct 2017
Posts: 3
piecevcake is on a distinguished road
Default Code for word 2007 please??? Formatting objects inside a canvas

Hi,

I tried this code in word 2007 but it returns error "The item with the specified name wasn’t found."


Is there different code that would work in 2007 please?
Reply With Quote
  #10  
Old 10-23-2019, 10:09 PM
macropod's Avatar
macropod macropod is offline Programmatically make text box borders invisible Windows 7 64bit Programmatically make text box borders invisible Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The same macro code in post #1 works in all Word versions from Word 97 to date. Presumably you're referring to the code in post #3, but your document lacks a shape named "MainCanvas".
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 10-28-2019, 08:16 PM
piecevcake piecevcake is offline Programmatically make text box borders invisible Windows 8 Programmatically make text box borders invisible Office 2007
Novice
 
Join Date: Oct 2017
Posts: 3
piecevcake is on a distinguished road
Default Oh

Thanks for clarifying.
Reply With Quote
Reply

Tags
vba change textbox word

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop through controls, make certain controls invisible MacroWizard Word VBA 2 11-10-2015 02:36 PM
Programmatically make text box borders invisible How to make Section headers (Header 2) invisible at print time? inframan Word 7 08-10-2012 09:39 PM
Programmatically make text box borders invisible How do I make invisible the lines in the table Snvlsfoal Word Tables 1 08-11-2011 05:45 AM
Object set to invisible yet I can still move its (invisible) animation paths?? seanspotatobusiness PowerPoint 0 05-23-2011 03:39 AM
Programmatically make text box borders invisible Make text invisible to printer ilkks Word 2 05-06-2011 04:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft