Results 1 to 2 of 2

Thread: Microsoft Word - Macro that Prompts User for Number of Tables to Be Copied and Pasted

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    1

    Question Microsoft Word - Macro that Prompts User for Number of Tables to Be Copied and Pasted

    I have a Microsoft Word document that contains a table with form fields.

    I would like it set up so that when the user first opens up the document, Microsoft Word prompts the user "how many additional tables" they want in addition to the one that already exists in the document.

    The macro would then select and copy, then paste the table "that many times" underneath.

    Unfortunately I don't know jack about Visual Basic. Can anyone here help me out?

  2. #2
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: Microsoft Word - Macro that Prompts User for Number of Tables to Be Copied and Pasted

    try this.

    Code:
    Private Sub Document_Open
    
    'declare variables
    Dim intNumberOfTables As Integer
    Dim MyCount As Integer
    
    'get input from user
    intNumberOfTables = InputBox("Please enter the number of tables", "Table Numbers")
    
    'copy current table
        'Selection.WholeStory [edit] This is incorrect and would copy the tables that you paste as well, so your table number would be exponential to the number you actually want.
        Selection.Tables(1).Select 'this should be ok, you will need the index number of your table though.
        Selection.Copy
    
    'repeat paste for number input by user
    For MyCount = 1 To intNumberOfTables 'changed from 0 start to 1
    
        Selection.InsertBreak Type:=wdPageBreak
        Selection.PasteAndFormat (wdPasteDefault)
    
    Next
    
    'confirm completion
    msgbox "Process COmplete",vbOKOnly +vbInformation ,"Complete"
    
    end sub
    Last edited by Br1an_g; Mar 25th, 2005 at 05:39 AM.
    if you fail to plan, you plan to fail

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width