Macro For Text Box

Page 1 of 1 (8 items)
This post has 7 Replies | 1 Follower

Posts 170
NYSERVANT | Forum Activity | Posted: Fri, Jun 26 2015 10:09 PM

I have been trying to figure out how to build a macro (or something else if it is easier) to be a single button I can push on my toolbar to create the code for the textbox but increasing a number each time.  I have been trying different things but I am not very good at these things.  Anyone ever find a way to make this work?

For Example:

  If I click a button this appears 

{{input id=QUESTION_1 | type=text | Lines=4 | prompt=“Type”}}

and then when I push the "text box increase" macro it will automatically increase to

{{input id=QUESTION_2 | type=text | Lines=4 | prompt=“Type”}}


Posts 24842
Forum MVP
Dave Hooton | Forum Activity | Replied: Fri, Jun 26 2015 10:30 PM

Please see & then clarify your query


Windows & Android

Posts 170
NYSERVANT | Forum Activity | Replied: Wed, Jul 1 2015 8:37 AM

Hi Dave,

  I'll try to explain it a little more.  I've gone to the wiki before and tried to figure something out on my own for a while but hoped perhaps there was someone more computer savy than I am.

  Typically for some of the other functions in a personal book I've programmed a macro to perform the function for me (so I don't have to type it out each time).  But this is easy for something that is always the same information.  

  I was hoping to build a macro that would work quickly for putting a text input box into a book.  Where it would automatically increase the number by 1 each time I run the macro so I don't have to go in and remember the last number I used in the book.  

  I have found macro's that will allow you to run it that it will increase numbers for things like invoice numbers and such.  But it is beyond my simple understanding of macros.  So it seems to me that it would be possible...just someone would have to know what they are talking about...which I do not lol

 I hope this clarifies a little bit.  

Posts 24842
Forum MVP
Dave Hooton | Forum Activity | Replied: Wed, Jul 1 2015 6:36 PM

Automatically increasing by one would be a problem if you didn't have a way to reset the count for a new PB, so I think it would be better to do it manually.


Windows & Android

Posts 1699
Robert M. Warren | Forum Activity | Replied: Thu, Jul 2 2015 7:28 PM

Mr. Servant:

See if this works: 

As you probably know, this is a Word template which, when double-clicked in a file explorer window, will open a new document which will save as a .docx by default. This template includes the macro, but also contains the kludge for storing certain info we need to do the input boxes.

If you examine the Tags property (Word calls them Keywords internally) by clicking File (in 2010 or 2013) and looking on the right side of the window, you'll see this text string:    QUESTION, 1, 4, "Type", 1     This is (in order)  1. the ID prefix, 2. the starting number for the IDs, 3. the number of Lines, or width number (depending on the value in another field), 4. the prompt, and 5. the Line or Width field (1 is Line; 2, or anything other than 1, is Width).

The macro, which I have assigned to Ctrl+L (because I don't think that one is used otherwise), extracts these details and enters text like this:

{{input id=QUESTION_1 | type=text | Lines=4 | prompt="Type"}}   and a new paragraph. It then increments the second field by 1 and saves the string back to properties. You keep composing your PB, save it when you need to, and the values will persist in the docx for when you open it and edit some more. [EDIT:  Duh Robert, the document in progress must be saved as a .docm file while still in the process of editing, or the macro will be killed. The final edition will need to be saved as a .docx, at which point also the Tags can be used for their real purpose, if needed.]

The template, of course won't change, unless you change it and save it as a template. Maybe you decide QUESTION should be NOTE or something. One important item:  Make sure to always include quotes around the prompt ("Type" in this case), should you decide to change it. You must also always delimit with commas (the spaces are optional, but make it easier to read). If you should need to specify Width, instead of Lines (they're mutually exclusive), just change the last field to 2 (from 1). These changes can also be made each time a new document is started from the template.

I've tested this, but we live in a fallen world, so let me know if you have any trouble. [edited out TMI (too much inflammation)] I have purposed to discontinue posting on the forums, but I will read them and occasionally provide this kind of help, such as I am able.

Win 10 Android 8.1 Fire OS 5

Posts 74
Lane McKay | Forum Activity | Replied: Fri, Jul 3 2015 7:30 AM

I just tried using this macro, as described, and when I Ctrl L, the only thing I see is the text string

{{input id=QUESTION_2 | type=text | Lines=4 | prompt="Type"}}

on the screen. Each time I invoke the macro, the QUESTION_X increases.

My doc is saved as the Docm format. I even tried inserting a text box manually and invoking the macro.

Interesting and would like to see how NY Servant is using other macros in the PB.

Posts 1699
Robert M. Warren | Forum Activity | Replied: Fri, Jul 3 2015 8:53 AM

Lane:  That text string becomes an input text box when compiled as a Personal Book.

To be more clear, here is the sequence for creating a PB with text input boxes using this template:

  1. Double-click the template in an explorer window.
  2. For the time being, save the new document as a .docm file, to preserve the existence of the macro.
  3. Begin your document, invoking Ctrl+L at the places where you want input boxes, the benefit being that all that text is auto and each box is assigned a unique ID.
  4. When you are satisfied that your document is ready to compile, save it as a .docx. You might even consider keeping an original in the docm format, incase you need editing with more boxes later.

Hope that helps.

Win 10 Android 8.1 Fire OS 5

Posts 74
Lane McKay | Forum Activity | Replied: Fri, Jul 3 2015 9:53 AM

Followed your steps and voila, it works. Didn't quite grasp the fact that I had to go through the whole procedure, including compiling the PB before I would see the results. Duh!

It (PB) even saves the info I type into the text box when I close it and that when I reopen the PB, that info is still there. Nice function. Hope there are more like this.

Thanks, Robert.

Page 1 of 1 (8 items) | RSS