MS Office Forum / Word / Programming / November 2007
VBA code to position a frame object...
|
|
Thread rating:  |
Bill Foley - 19 Nov 2007 03:06 GMT Hey Gang,
Word 2003, Windows XP
I have a document I am developing for a client (friend) that requires the use of outline numbering. I have created the STYLES, etc. and all is going pretty good. I ran into a problem getting a line (for initials) showing completion of a step. Got some great help from Klaus and John!
My next dilemma is occasionally I will need another initial line (sort of a verification line). I have created a frame and saved it as an AutoText to insert from a button on a toolbar. However, I need some code to "exactly position" the frame. Reason is, this frame has a line and some letters exactly below the line and the text disrupts the flow of the paragraph (if you know what I mean.
For example, I need the position the second line and text (all within a frame) to get this look:
____ ____ A. This paragraph might be multiple lines and the "INIT" must stay below the second line. INIT
This is easy if the paragraph is a single line, but it isn't always the case and the frame needs to not impact text flow but MUST be in that position.
Any ideas? Sampe code you can send me to?
TIA!
Bill
Jean-Guy Marcil - 19 Nov 2007 19:14 GMT Bill Foley was telling us: Bill Foley nous racontait que :
> Hey Gang, > [quoted text clipped - 23 lines] > that position. > Any ideas? Sampe code you can send me to? I am no sure I follow...
Can you post a sample paragraph (that has more than one line) before the autotext is added, then show us the result you want after the Autotext is added. Finally, include what you get now (the wrong result).
Remember that a frame is part of the text flow. It might not be possible to do what you want with frames; then you would need a textbox instead. Maybe... if only I understood what you want!
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Bill Foley - 20 Nov 2007 01:25 GMT Jean,
I guess you are right. I am going to want a text box, but I need code to exactly position it. Right now I have code that puts in a line at the left hand margin (thanks to some other MVPs help). In some cases I need another line with some letters below the line. All this needs to be within an outline numbered style. I will try and cut down on the text so it will appear correctly.
____ ____ 1.1 The "INIT" must stay below the second line. INIT
____ ____ 1.1.1 It could be this style INIT
The first line and style are all automated. What I need is a text box with a Line and the letters "INIT" below it to fall in the spot shown above. The problem is that the paragraph might be several lines so the INIT can't be manually put there by SHIFT+ENTER, TAB, etc.
Sometimes the second line is not needed.
____ 1.1 Sample style without second line.
____ 1.1.1 Another sample without the line.
Instead of trying to develop a bunch of different styles and insert the lines within the Style Customize dialog box, I would like an automated method.
Hope this clarifies. Thanks in advance!
Bill
> Bill Foley was telling us: > Bill Foley nous racontait que : [quoted text clipped - 36 lines] > to do what you want with frames; then you would need a textbox instead. > Maybe... if only I understood what you want! Jean-Guy Marcil - 20 Nov 2007 03:08 GMT Bill Foley was telling us: Bill Foley nous racontait que :
> Jean, > [quoted text clipped - 27 lines] > > Hope this clarifies. Thanks in advance! You still have not shown us what happens with multi-line paragraphs. Can you post samples of non-indented paragraphs with a before and after... (I.e. before the code and after the code). With single line paragraphed is easy, but it would be helpful for all to see exactly what happens with more than one line.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Bill Foley - 20 Nov 2007 04:20 GMT Jean.
Thats just it. I haven't been able to accomplish this yet. What I have done in the past is to hit SHIFT+ENTER to move down, change the before and after paragraph settings and get the INIT as close to the line as possible. The first line is done via code (could not get two lines, though). The second line is a drawn object placed next to the first line. What I am wanting is to make the second line and the INIT text part of a text box and position it via VBA as shown below, such that multi lines in a paragraph do not affect it.
If you want, I'll be happy to send a sample offline. If so, send me a message to billfoleyatcharterdotnet.
Thanks!
Bill
> Bill Foley was telling us: > Bill Foley nous racontait que : [quoted text clipped - 36 lines] > With single line paragraphed is easy, but it would be helpful for all to > see exactly what happens with more than one line. Jean-Guy Marcil - 20 Nov 2007 06:38 GMT Bill Foley was telling us: Bill Foley nous racontait que :
> Jean. > > Thats just it. I haven't been able to accomplish this yet. What I I understand that you do not have the code to do what you want. I was just asking you to post a manual version of the result you want from a multi line paragraph.
For example, if you have:
____ 1.1 Sample style with second line some more text on the second line and on a third line.
Am I correct in thinking that the result you want is:
____ ____ 1.1 Sample style with second line INIT some more text on the second line and on a third line.
???
If so, will there always be space for the new text to be inserted between the ____ and the beginning of the text on the first line? Are the lines after the first always aligned as in my example, or do you sometimes have something like: ____ 1.1 Sample style with second line some more text on the second line and on a third line.
What if it is a single line paragraph, is it OK to add a new line for INIT and therefore push the rest of the text down the page by one line? Like:
____ 1.1 Sample style with one line.
Another paragraph.
would become:
____ ____ 1.1 Sample style with one line. INIT
Another paragraph.
???
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Bill Foley - 20 Nov 2007 14:34 GMT Jean,
Thanks for your patience and help as I explain things better. See comments below:
> Bill Foley was telling us: > Bill Foley nous racontait que : [quoted text clipped - 18 lines] > INIT some more text on the second line and > on a third line. BF: You are correct! This is what I want to accomplish. Actually the STYLE has a hanging indent so the text is always aligned further to the right.
> ??? > [quoted text clipped - 5 lines] > some more text on the second line and > on a third line. BF: They are ALWAYS aligned as in your previous example (hanging indent based on STYLE). They NEVER run into the area where the text box would be, so there is always room for the line and INIT.
> What if it is a single line paragraph, is it OK to add a new line for INIT > and therefore push the rest of the text down the page by one line? Like: [quoted text clipped - 9 lines] > > Another paragraph. BF: Yes, that would be fine. The STYLE already has 12 pt before and 12 pt after so there is spacing. Since subsequent paragraphs will be indented based on its outline numbered style it isn't absolutely necessary to have additional space. Basically, ONE method would fit all!
> ??? BF: Salut to you too!
> _______________________________________ > Jean-Guy Marcil - Word MVP > jmarcilREMOVE@CAPSsympatico.caTHISTOO > Word MVP site: http://www.word.mvps.org Jean-Guy Marcil - 20 Nov 2007 17:48 GMT Bill Foley was telling us: Bill Foley nous racontait que :
> Jean, > [quoted text clipped - 27 lines] > the STYLE has a hanging indent so the text is always aligned further > to the right. Just to make sure, this means that the "____" in the following paragraph is part of the style definition (part of the numbering formatting):
____ 1.1 Sample style with second line some more text on the second line and on a third line.
???
The code should insert ____ INIT
between the already existing "____" and the paragraph text itself.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Bill Foley - 21 Nov 2007 04:00 GMT Jean,
Actually the first ____ is coded in thanks to some work from John. It can be put in or taken out by an icon on a toolbar. I had originally wanted to put the ____ in the Style/Customize dialog box, but the lower levels (1.1.1 and 1.1.1.1) wouldn't allow that much space.
In other words, this wouldn't work:
____ 1.1 This worked
____ 1.1.1 This did not work (apparently there is a limitation to the number of characters in the Customize window.
Also, I need the lines to be towards the margin. Otherwise I could have done the following in the STYLE:
____ 1.1 Text
____ 1.1.1 Text
____ 1.1.1.1 Text
So that won't work for me either (even though it would be easy to do in the Customize dialog box).
Hope that answers your questions. Feel free to pop back if you have more. Hope you're getting close!
TIA!
Bill
> Bill Foley was telling us: > Bill Foley nous racontait que : [quoted text clipped - 45 lines] > > between the already existing "____" and the paragraph text itself. Russ - 21 Nov 2007 04:36 GMT Bill, Could a variation of John's code also do what you want? Can you post the code John used to insert the ____? Maybe we could adapt it to enter more things in the indented areas.
> Jean, > [quoted text clipped - 77 lines] >> >> between the already existing "____" and the paragraph text itself.
 Signature Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Bill Foley - 21 Nov 2007 04:50 GMT Russ,
The extra line really isn't the problem, it is the initials below the second line that is the problem. That MUST be part of a textbox because it could disrupt text flow in the paragraph if it wasn't. I was just hoping to have the second line AND the initials below it part of a textbox that can be positioned.
I am starting to assume that finding some VBA code to exactly position a textbox is not going to happen here. I have searched everywhere and can't seem to find anything (and I have a vast archive of macros)!
I appreciate the time you all have put into this.
Thanks!
Bill
> Bill, > Could a variation of John's code also do what you want? [quoted text clipped - 89 lines] >>> >>> between the already existing "____" and the paragraph text itself. Russ - 21 Nov 2007 05:15 GMT Bill, Although, come to think of it, John's code probably does not put anything in the indent area since it is on the first line of a hanging indent style and the first line isn't indented. To put something in an indented area, it would have to be on the graphics layer, which is different than the text layer. The user wouldn't be able enter text in the graphics layer, if we just drew a graphic there.
So does the document need to be filled out before it is printed?
We might put an graphics object there like a textbox or undo the hanging indent for the first paragraph and maybe manipulate the indents after we insert new text near the left margin.
Another way to do this might be to use a borderless (unseen) table for formatting and anchoring text, for instance, one row with two tall cells to separate what you want on the left side from what flows on the right side.
> Bill, > Could a variation of John's code also do what you want? [quoted text clipped - 82 lines] >>> >>> between the already existing "____" and the paragraph text itself.
 Signature Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Bill Foley - 21 Nov 2007 20:53 GMT See comments below:
> Bill, > Although, come to think of it, John's code probably does not put anything [quoted text clipped - 7 lines] > > So does the document need to be filled out before it is printed? No, they are normally printed out and initials written in the blank lines by hand.
> We might put an graphics object there like a textbox or undo the hanging > indent for the first paragraph and maybe manipulate the indents after we > insert new text near the left margin. If that works, that would be great!
> Another way to do this might be to use a borderless (unseen) table for > formatting and anchoring text, for instance, one row with two tall cells > to > separate what you want on the left side from what flows on the right side. I really didn't want to resort to tables because some of these documents are hundreds of pages and most of them all have some sort of initial block needed on every page. That was my first option to have two small columns at the left hand margin and manipulate the style indents to accomodate it. Unfortunately, that is NOT an option.
>> Bill, >> Could a variation of John's code also do what you want? [quoted text clipped - 90 lines] >>>> >>>> between the already existing "____" and the paragraph text itself. Bill Foley - 26 Nov 2007 13:24 GMT Hey Gang,
Hope everyone had a great Thanksgiving (for those who celebrate)! Just wondering if this thread is dead or if anyone found some code or figured out a way to code this.
Thanks!
Bill
> Hey Gang, > [quoted text clipped - 28 lines] > > Bill Jean-Guy Marcil - 26 Nov 2007 20:54 GMT Bill Foley was telling us: Bill Foley nous racontait que :
> Hey Gang, > > Hope everyone had a great Thanksgiving (for those who celebrate)! Just > wondering if this thread is dead or if anyone found some code or > figured out a way to code this. You already have code that was provided by somebody else that you use to add the first "____". Without seeing what that code does, it is difficult to help out as the code we might suggest might interfere with the other one or create problems.
Also, you stated that you cannot use tables (as suggested by Russ). I did not understand what that wasn't an option as this would be the easiest. If you worry about the table interfering with already existing ones, all you need to do is to have a ¶ before and one after that are set as hidden. This way the table you insert will no interfere with the document content. The other option is to create an image/picture of the two lines and INIT text. Then you just need to insert the picture floating over the text.
 Signature Salut! _______________________________________ Jean-Guy Marcil - Word MVP jmarcilREMOVE@CAPSsympatico.caTHISTOO Word MVP site: http://www.word.mvps.org
Bill Foley - 26 Nov 2007 22:13 GMT Sorry if it sounds like I am trying to hide something but I PAID for the code for the first line and as such don't want to post it up here. If you want me to send it offline, send me a message to billfoleyatpttincdotcom.
Other than that, I appreciate everyone's efforts to help.
Thanks!
Bill
> Bill Foley was telling us: > Bill Foley nous racontait que : [quoted text clipped - 17 lines] > The other option is to create an image/picture of the two lines and INIT > text. Then you just need to insert the picture floating over the text.
|
|
|