Text box blues

O

Oz Springs

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
 
J

Jay Freedman

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
 
O

Oz Springs

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
 
J

Jay Freedman

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
 
O

Oz Springs

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
 
J

Jay Freedman

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

Steve Rindsberg

This is where you learn that the macro recorder is a piece of dingo dung
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. ;-)
 
O

Oz Springs

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
 
J

Jonathan West

Oz Springs said:
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.

In the VBA editor, press F2 to bring up the Object Browser window. Lists of
objects & properties as far as the eye can see....
 
O

Oz Springs

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
 
J

Jonathan West

Oz Springs said:
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.

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
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?

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

Steve Rindsberg

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

Oz Springs

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top