PDA

View Full Version : Table Help



MontySharpei
04-08-2009, 06:07 AM
Hello,

I want to be able to press a button and the macro will copy the table above the button and create a blank duplicate underneath the copied table. In the example attached I have been able to find a macro that copies the table but unable to get the deletion to work. Can anyone assist ?

fumei
04-08-2009, 11:22 AM
You say you want to:

"be able to press a button and the macro will copy the table above the button and create a blank duplicate underneath the copied table."

Then say:

"a macro that copies the table but unable to get the deletion to work."

Ummm, WHAT deletion? You do not state what it is you want deleted.

MontySharpei
04-08-2009, 11:37 AM
Apologies,

Suppose I have 2 contacts. I want to be able to enter contact 1 details ie: name, address, telephone, and GPS code, in the table.

Then when I click the button, and what I want is table 1 reproduced but blank ready for contact 2 details.

At the moment it produces an exact copy of the table (inother words Contact 1 again, and I have to delete the contents to then in contact 2's details .....

fumei
04-08-2009, 12:05 PM
1. I personally do not like commandbuttons in documents. Especially ones that have a caption of "CommandButton1". Are you wedded to this?

2. you are not using Option Explicit. I strongly recommend you use it. Start now. I have put Option Explicit into the code module of the file I am attaching back.

3. there are a number of ways of doing what you ask. The way I did it in the attached returned file (Test_Gerry.doc) is NOT, repeat NOT, the way I would do it myself, if I was designing this.

However, it does do what you asked for:

"table 1 reproduced but blank ready for contact 2 details."

4. I created two proper Styles (myTableText and myBasicText) for the attached document. I strongly suggest you start using Styles. Word is designed around Styles.

MontySharpei
04-08-2009, 01:57 PM
thankyou,

what would be a better way ??

fumei
04-08-2009, 02:19 PM
It depends. Is this going to be distributed?

Option_A: an AutoText of the table with no content in the second column.

Option_B: create a table from scratch, put the text into the approrpriate cells.

Option_C: a userform that both creates the table AND collects the data to go into the second column

Option_D: a userform that inserts a AutoText of a blank table (although with the text in the first column, Name...etc.), collects the data for the table, makes a table object of the newly inserted AutoText, and then puts the collected data into the second column of the table object.

Any of the above would work, but depending on circumstances, myself I would lean towards Option_D. The critical factor would be the AutoText. If it is distributed then you have to make sure the other person HAS access to the AutoText.

If it is to be distributed, then Option_C would be best, as it does not use AutoText.

fumei
04-08-2009, 02:56 PM
Here is a demo.

You can call the userform by either clicking "Make New Table" on the top toolbar; OR by pressing Alt-n.

The userform starts with the cursor in the Name field. Type something, press Tab, the cursor goes to the Address field. Type something, press Tab, the cursor goes to the Tel field. Type something, press Tab, the cursor goes to the GPS Code field. Type something, press Tab, the cursor goes to the Make New Table button.

Press Enter....the table is created with the data from the textboxes.

If you want to make another table, simply start again, fill in the textboxes, and click Make New Table.

When you are done, press....Done.

Any time you want to make a new table, click "Make New Table" on the top toolbar, OR press Alt-n.

The userform displays and you can make a new table.

Now....as it stands, the new tables are created at the Selection - where the cursor is in the document. Although each time a table is created that Selection is moved to the end of the document.

However, placement is a fairly trivial thing to do, so if you wanted specific placement, all you need to do is define your requirements.