Consulting

Results 1 to 3 of 3

Thread: VBA, MS Word Macro - Prompt # Tables, Copy + Paste # of Tables

  1. #1
    VBAX Newbie
    Joined
    Mar 2005
    Posts
    1
    Location

    Question VBA, MS Word Macro - Prompt # Tables, Copy + Paste # of Tables

    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 much about Visual Basic. On the bright side, I do know how to make macros in Word. Can anyone here help me out?

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    In the Word VBEditor (Alt+F11), find your way to the document_open event and insert this code [VBA]Dim Response As Integer, i As Integer

    Response = InputBox("Prompt text here", "How many extra tables?")

    If Response > 0 Then
    ThisDocument.Tables(1).Select
    Selection.Copy
    For i = 1 To Response
    Selection.EndKey Unit:=wdStory
    If Selection.Next(wdCharacter, -1) <> Chr(13) Then Selection.TypeParagraph
    Selection.Paste
    Next
    End If[/VBA] you should get something close to the result you're after
    K :-)

  3. #3
    Knowledge Base Approver
    Space Cadet
    VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    And if your document is a template then you can place the code in the AutoNew event procedure which would mean that the user isn't prompted everytime to insert tables, just when they use the doc for the first time, unless this is what you want to happen??



    Andrew ;?
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


Posting Permissions

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