Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Concatenating to form a variable name (Word 2000)

    I know this is an easy question for you pros, if I can just figure out how to word it.

    I have variables called strBookmark1, strBookmark2, strBookmark3, strBookmark4. I then want to take advantage of the For command and each iteration of 1, 2, 3, 4 to combine with the root name of the variable (strBookmark), which will be used as an argument. Here's the basis of the code I'm trying to work out:

    *****************
    Dim strBookmark1 As String, strBookmark2 As String, strBookmark3 As String, _
    strBookmark4 As String, rngDateText As Range, i As Integer

    strBookmark1 = "Timesheet"
    strBookmark2 = "Expenses"
    strBookmark3 = "Income"
    strBookmark4 = "Total"

    For i = 1 To 4
    Set rngDateText = ActiveDocument.Bookmarks(strBookmark & i).Range
    '[More code here]
    Next
    *****************
    I know that the "strBookmark & i" is not working. I need the macro to recognize the value of strBookmark1, strBookmark2, etc., as the argument for Bookmarks.

    Thanks for any help you can give me.

    - Linda

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Concatenating to form a variable name (Word 2000)

    Hi Linda

    This might work for you:
    <pre>Public Sub bmTest()
    Dim strBookmark(5) As String, rngDateText As Range, i As Integer

    strBookmark(1) = "Timesheet"
    strBookmark(2) = "Expenses"
    strBookmark(3) = "Income"
    strBookmark(4) = "Total"

    For i = 1 To 4
    Set rngDateText = ActiveDocument.Bookmarks(strBookmark(i)).Range
    '[More code here]
    MsgBox rngDateText 'Here for testing only
    Next 'i

    End Sub
    </pre>


    Alan

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Concatenating to form a variable name (Word 2000)

    Alan,

    Yes! That works great! Thank you very much.

    - Linda

Posting Permissions

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