Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Jan 2002
    Posts
    74
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi,

    I am trying to create a macro where the user enters the number of rows and then a table is created with that number of rows.

    It's actually a little more sophisticated than that but I'm stuck at the point where the macro won't use the bookmark value to create the number of rows.

    This is the tricky line:

    Selection.Cells.Split NumRows:=ActiveDocument.Bookmarks("NumRows").Selec t, NumColumns:=2, MergeBeforeSplit:=True

    (The actual task involves splitting a cell in an existing table into x rows and two columns.)

    Using an Ask field I know how many rows there should be (NumRows) but Word won't run the macro with the syntax above.

    How do I write the macro such that the numeric value of NumRows is accepted?


    Multiple TIAs,



    David

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 28 Times in 27 Posts
    Hi David,

    Just looking at the line of code, 'NumRows' is looking for a number value (like an Integer or Long) - just the same way that NumColumns is accepting "2" as a value.

    "Activedocument.Bookmarks("NumRows").Select" is a method, and does not by itself return a value.

    To return the value of the NumRows bookmark as a string, you could use

    Activedocument.Bookmarks("NumRows").Range.Text

    and to turn that into a number value you could use CInt(Activedocument.Bookmarks("NumRows").Range.Tex t)

    so something like

    Selection.Cells.Split NumRows:=CInt(Activedocument.Bookmarks("NumRows"). Range.Text), NumColumns:=2, MergeBeforeSplit:=True

    should work - with the caveat that I haven't tested it!

    Gary

  4. #3
    Star Lounger
    Join Date
    Jan 2002
    Posts
    74
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks very much Gary!

    I searched the web for quite a bit to find out what I thought would be relatively straightforward info but I couldn't find it. So I very much appreciate your efforts.

    It wasn't necessary to convert the bookmark to a number as it receives a numerical value when the user completes an ASK field.

    Best,

    David

Posting Permissions

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