MS Office Forum / Word / Programming / January 2005
Text box blues
|
|
Thread rating:  |
Oz Springs - 04 Jan 2005 15:55 GMT I created a text box by my usual way (recording it) and someone very kindly helped me with a code to set it more professionally by using ³dim² while all recorded things are ³selection².
The problem is that I have set more features using ³selection² and everytime I try to set these into ³Dim² code, using VB Help, I get error messages.
My selection macro works fine except that I want to set the text box anchor point at the top paragraph of the document which does not seem to be recordable. I want to set it there so if text directly above it moves, the text box stays where it is.
This is the code I was given:
Dim myTextBox as Shape
Set myTextBox = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=42.55, Top:=667.65, _ Width:=340#, Height:=69#, _ Anchor:=ActiveDocument.Paragraphs(1).Range)
How can I make my text box anchor where I want it to while keeping all my recorded settings? Alternatively, would it be better to move everything to the ³Dim² way in which case I¹ll give you the recorded settings I wanted to change:
TextframemarginLeft=0# (also right, top & Bottom) Selection.ShapeRange.Fill.Visible=msoFalse Selection.ShapeRange.Line.Visible-msoFalse
Thanks for any help
Oz
Jay Freedman - 04 Jan 2005 17:15 GMT Hi Oz,
Yes, it would be better to change all the recorded stuff so it doesn't use the Selection. To do that, you just replace the "Selection.ShapeRange" with "myTextBox":
Dim myTextBox As Shape
Set myTextBox = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=42.55, Top:=667.65, _ Width:=340#, Height:=69#, _ Anchor:=ActiveDocument.Paragraphs(1).Range)
myTextBox.TextFrame.MarginLeft = 0 myTextBox.TextFrame.MarginRight = 0 myTextBox.TextFrame.MarginTop = 0 myTextBox.TextFrame.MarginBottom = 0 myTextBox.Fill.Visible = msoFalse myTextBox.Line.Visible = msoFalse
 Signature Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org
> I created a text box by my usual way (recording it) and someone very > kindly helped me with a code to set it more professionally by using [quoted text clipped - 31 lines] > > Oz Oz Springs - 04 Jan 2005 18:46 GMT Hi Jay
Thank you very much, this works. And it is a very neat solution for the future when I want to change selection items into dim items.
There is only one other problem and that is I need to put a table in the text box (so I can have the text centred), type some text and select it so the user can start typing there straight away. In my recording I could do this automatically, but I can¹t do this using myTextBox. I have tried gotoMyTextBox and a couple of other things (gotoobject, what etc.) but they don¹t work.
How do I link myTextBox to the table created by macro recording?
Many thanks
Oz
On 4/1/05 17:15, in article eyynFEo8EHA.4004@tk2msftngp13.phx.gbl, "Jay Freedman" <jay.freedman@verizon.net> wrote:
> Hi Oz, > [quoted text clipped - 16 lines] > myTextBox.Fill.Visible = msoFalse > myTextBox.Line.Visible = msoFalse Jay Freedman - 04 Jan 2005 19:44 GMT Hi Oz,
This is where you learn that the macro recorder is a piece of dingo dung suitable only for finding out the names of things, so you can look them up and then write your own code.
You're welcome to study this macro and then come back and ask about anything you don't understand:
Sub MakeAbox() Dim myTextBox As Shape Dim myRange As Range Dim myTable As Table
Set myTextBox = ActiveDocument.Shapes.AddTextbox( _ Orientation:=msoTextOrientationHorizontal, _ Left:=42.55, Top:=667.65, _ Width:=340#, Height:=69#, _ Anchor:=ActiveDocument.Paragraphs(1).Range)
With myTextBox With .TextFrame .MarginLeft = 0 .MarginRight = 0 .MarginTop = 0 .MarginBottom = 0 End With .Fill.Visible = msoFalse .Line.Visible = msoFalse End With
Set myRange = myTextBox.TextFrame.TextRange
myRange.Collapse direction:=wdCollapseStart
Set myTable = ActiveDocument.Tables.Add( _ Range:=myRange, numrows:=1, numcolumns:=3)
With myTable .Borders.Enable = False With .Cell(1, 2).Range .ParagraphFormat.Alignment = wdAlignParagraphCenter .Text = "Type here" .Select End With End With End Sub
 Signature Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org
> Hi Jay > [quoted text clipped - 36 lines] >> myTextBox.Fill.Visible = msoFalse >> myTextBox.Line.Visible = msoFalse Oz Springs - 05 Jan 2005 00:03 GMT HI Jay Thank you very much for this. Amazingly I was able to add bits and pieces to this macro (after quite a bit of trial and error) in order to get the setup I wanted.
I have had quite a few harsh words to say about Word¹s pretensions as a page layout application, and particularly about text boxes which I try to avoid having unless there is no other alternative, but I have found that the macro recorder has helped me lots of times to get something useful working. I have tried recording in other apps and Word¹s is far, far better than anything else I¹ve used.
But now I know (dimly) the ³dim² setup and this is going to be quite handy for work to come.
Thanks very much for your help
Oz
On 4/1/05 19:44, in article eRZvcXp8EHA.1264@TK2MSFTNGP12.phx.gbl, "Jay Freedman" <jay.freedman@verizon.net> wrote:
> Hi Oz, > [quoted text clipped - 43 lines] > End With > End Sub Jay Freedman - 05 Jan 2005 04:17 GMT Hi Oz,
I'm glad I was able to further your education. Come back often! :-)
Part of the problem is that Word has almost *no* pretensions as a page layout application, though it may sometimes look like one. It's fundamentally a word processor, with some page layout capabilities that users have demanded over the years. MS has always maintained that if you want a page layout program you should use Publisher (or one of its Competitors That Shall Not Be Named). This accounts for things like Word's inability to flow text to fill the space on the page before a picture or textbox, or to nail a textbox onto a particular page.
-- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org
>HI Jay >Thank you very much for this. Amazingly I was able to add bits and pieces to [quoted text clipped - 14 lines] > >Oz Steve Rindsberg - 05 Jan 2005 02:40 GMT > This is where you learn that the macro recorder is a piece of dingo dung > suitable only for It's been improved in 2003 then, has it?
;-)
Jay Freedman - 05 Jan 2005 04:24 GMT >> This is where you learn that the macro recorder is a piece of dingo dung >> suitable only for > >It's been improved in 2003 then, has it? > >;-) Not noticeably. I think for the next Office they're working on moose manure. :-b
-- Jay
-- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org
Steve Rindsberg - 05 Jan 2005 15:55 GMT > >> This is where you learn that the macro recorder is a piece of dingo dung > >> suitable only for [quoted text clipped - 5 lines] > Not noticeably. I think for the next Office they're working on moose > manure. :-b To keep it in synch with the Help system. Of course! I should have know. ;-)
Oz Springs - 06 Jan 2005 20:47 GMT On the subject of Help for VB, is there anywhere I can find an explanation of the properties for when I am setting up a userform? I can guess most of them, but some of them are rather obscure. I¹d prefer to have a list (like the properties themselves) or lists - one for the form, another for a combo box etc. rather than looking up Help for each item. In any case sometimes the Help doesn¹t explain the properties very well.
Thanks for any help
Oz
On 5/1/05 15:59, in article VA.00000f6e.6e2affd1@localhost.com, "Steve Rindsberg" <abuse@localhost.com> wrote:
>>>> This is where you learn that the macro recorder is a piece of dingo dung >>>> suitable only for [quoted text clipped - 7 lines] > > To keep it in synch with the Help system. Of course! I should have know. ;-) Jonathan West - 06 Jan 2005 21:01 GMT > On the subject of Help for VB, is there anywhere I can find an explanation > of the properties for when I am setting up a userform? I can guess most of [quoted text clipped - 3 lines] > box etc. rather than looking up Help for each item. In any case sometimes > the Help doesn¹t explain the properties very well. In the VBA editor, press F2 to bring up the Object Browser window. Lists of objects & properties as far as the eye can see....
 Signature Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup
Oz Springs - 06 Jan 2005 21:35 GMT Thanks, I have just tried F2, but it doesn¹t seem to work on a Mac, so I fossicked around and View Menu has ³Object Browser² and command+b as the shortcut.
However, Object Browser is too complex for me! For instance, in the properties window there is an item called ³Tag² and when I looked this up in the Object Browser the explanation was ³property tag as string² and, in another section, that it was part of CommandBarControl. What I want is a list which explains what ³tag² and other property items do.
For example, one property I do understand is ³Caption² and an explanation of this could be ³type in the name you want the userform to display at the top of the window, for example ³Fax details². This is different from the (Name) property which must always be one word, for example ³frmFax².
Is there any such list available?
Thanks
Oz
On 6/1/05 21:01, in article #CO#yMD9EHA.3920@TK2MSFTNGP10.phx.gbl, "Jonathan West" <jwest@mvps.org> wrote:
>> On the subject of Help for VB, is there anywhere I can find an explanation >> of the properties for when I am setting up a userform? I can guess most of [quoted text clipped - 6 lines] > In the VBA editor, press F2 to bring up the Object Browser window. Lists of > objects & properties as far as the eye can see.... Jonathan West - 06 Jan 2005 21:49 GMT > Thanks, I have just tried F2, but it doesn¹t seem to work on a Mac, so I > fossicked around and View Menu has ³Object Browser² and command+b as the [quoted text clipped - 6 lines] > another section, that it was part of CommandBarControl. What I want is a > list which explains what ³tag² and other property items do. Different objects can have similarly-named properties which do different things. So you just have to look that up in the Help.
The aim of the Object Browser is to provide you with a quick reference as to what properties & methods are available for a particular object.
> For example, one property I do understand is ³Caption² and an explanation > of [quoted text clipped - 5 lines] > > Is there any such list available? You just have to dig through the Help for the detailed descriptions of the various properties. There's no intermediate level of detail between the Object Browser & the full Help.
 Signature Regards Jonathan West - Word MVP www.intelligentdocuments.co.uk Please reply to the newsgroup
Steve Rindsberg - 07 Jan 2005 01:05 GMT > Thanks, I have just tried F2, but it doesn¹t seem to work on a Mac, Ah. Any of us who complain too bitterly about Help in Windows should spend a week working in VBA on Mac. If it doesn't kill you, it makes you stronger. Or at least it makes your language stronger. And Windows feels REAL nice to come home to afterward. ;-)
Suggestion: if you need to do any serious VBA work, try to do it on a PC and port it back to the Mac, or run VPC and a copy of Windows and do the coding there. This has nothing to do with Mac vs PC religious wars; it's just that MS has not put the time/resources into Mac VBA that they have into the Windows version and it shows.
O'Reilly has a book worth looking at if you can find it: Visual Basic Controls in a Nutshell by Dictor. It's meant for VB rather than VBA and is Windows-specific, but most of the controls are quite similar, and the author does a good job of explaining them.
 Signature -- Steve Rindsberg, PPT MVP PPT FAQ: www.pptfaq.com PPTools: www.pptools.com
================================================
Oz Springs - 07 Jan 2005 11:38 GMT >Suggestion: if you need to do any serious VBA work, try to do it on a PC and > port it back to the Mac, or run VPC and a copy of Windows and do the coding > there. Highly unlikely I¹ll ever be doing any serious VBA work. I¹m a ³go to bookmark² person who can do basic userforms - which go to bookmarks...
Thanks for the info. I am looking to buy the book you mention - probably 2nd hand as that¹s all that¹s available.
Oz
On 7/1/05 01:05, in article VA.00000f93.7545c02d@localhost.com, "Steve Rindsberg" <abuse@localhost.com> wrote:
>> Thanks, I have just tried F2, but it doesn¹t seem to work on a Mac, > [quoted text clipped - 21 lines] > PPTools: www.pptools.com > ================================================
|
|
|