Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Capture selected Background Pattern Shading (Word

    Dear All,

    I managed to do the following:

    Set dlgshadingborders = Dialogs(wdDialogFormatBordersAndShading)
    With dlgshadingborders
    .DefaultTab = wdDialogFormatBordersAndShadingTabShading
    .Show
    End With

    to launch the Format Borders and Shading dialog box.

    Could somebody show me how I could assign the selected Background pattern and colour to a variable when the user clicks OK, and that variable be used on the selected table?

    Thank you very much in advance.

    Regards
    Rid

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capture selected Background Pattern Shading (Word

    If you use the Show method, the color selected by the user will automatically be applied. If you want to set it yourself, you must use the Display method of the dialog. It doesn't apply the settings.

    Sub SetFillColor()
    Dim lngColor As Long
    If Selection.Information(wdWithInTable) = False Then
    MsgBox "Please position the insertion point in a table.", vbExclamation
    Exit Sub
    End If
    With Dialogs(wdDialogFormatBordersAndShading)
    .DefaultTab = wdDialogFormatBordersAndShadingTabShading
    .Display
    lngColor = .BackgroundRGB
    End With
    With Selection.Tables(1).Shading
    .Texture = wdTextureNone
    .ForegroundPatternColor = wdColorAutomatic
    .BackgroundPatternColor = lngColor
    End With
    End Sub

    The VBA help subject Built-in Dialog Box Argument Lists provides all available arguments for dialogs, but without any explanation.

  3. #3
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Capture selected Background Pattern Shading (W

    Thank you so much Hans.

    At last I am getting somewhere but not there yet. :-)

    I guess I did not make myself clear enough.

    The final objective of the code is to let user highlight alternate rows with selected pattern Style and Color.

    I am this far.

    ------------------------------
    Dim dlgshadingborders As Dialog
    Dim lastRow As Long
    Dim i As Integer
    Dim lngColor As Long

    Set dlgshadingborders = Dialogs(wdDialogFormatBordersAndShading)
    With dlgshadingborders
    .DefaultTab = wdDialogFormatBordersAndShadingTabShading
    .Display
    lngColor = .BackgroundRGB
    End With
    MsgBox lngColor
    lastRow = Selection.Information(wdMaximumNumberOfRows)
    If lastRow <= 3 Then
    MsgBox "No need for shading"
    Exit Sub
    End If
    For i = 3 To lastRow
    Selection.Tables(1).Rows(i).Select
    With Selection.Tables(1).Rows(i).Shading
    .Texture = wdTexture10Percent
    .ForegroundPatternColor = lngColor
    End With
    i = i + 1
    Next i
    -----------------------
    How can I shade the row with selected Texture style instead of fixing it to wdTexture10Percent ?

    Thank you so much in advance.

    Regards
    Rid

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capture selected Background Pattern Shading (W

    I'm sorry, I don't know how to do that using the dialog. The list of built-in dialog arguments doesn't include anything that refers to Texture.

    Perhaps the following will work:
    - In the code, select the first row you want to shade.
    - Then open the dialog with the .Show method.
    - When the user clicks OK, the settings will be applied to the selected row.
    - Store the texture and pattern settings of the row in variables.
    - Loop through the other rows and apply the settings.

    Note: you can loop through alternate rows as follows:

    For i = 3 To lastRow Step 2
    ...
    Next i

  5. #5
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Capture selected Background Pattern Shading (W

    Genius...genius....

    Thank you so much.....I have managed to solve it.

    Thank you.

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Capture selected Background Pattern Shading (W

    You don't specify which version of Word you wanted to do this alternate shading in. Word 2002 and 2003 both have Table Styles which allow for this thing to be applied automatically. The benefits of using a table style are that you don't need VBA code to apply it and the table automatically adjusts the banding if rows are added or subtracted.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Capture selected Background Pattern Shading (W

    Thanks Andrew.

    Maybe I should re-look into Table Autoformatting.

    At the current moment, I found using VBA for shading easier, as the table size (number of rows and columns) on the documents are more or less fixed, ie. hardly any addition to the size. Apart from the shading, I also did formatting to the cells contents paragraph, which undeniably can be done with Table Autoformatting too. But yes, I will definitely re-look into Table Autoformatting.

    Thank you once again. This forum has been super-resourceful.

    PS. I did put down the version of Word I am using (Word 2003), but I guess my subject matter was too long, that the version was pushed out the box.

    Regards
    Rid

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capture selected Background Pattern Shading (W

    Some browsers cut off the subject when you post.

  9. #9
    Star Lounger
    Join Date
    Feb 2005
    Posts
    61
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Capture selected Background Pattern Shading (W

    I used Firefox for this thread.

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Capture selected Background Pattern Shading (W

    Yes, FireFox is known to truncate the combined subject + version to 50 characters.

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Capture selected Background Pattern Shading (W

    The cut-off occurs, I believe, when you use Preview, which we definitely encourage. The subject part and the version part get added together, and then both are subject to the maximum field size of 50. IE handles this in a different way: instead of only passing the maxlength number of characters to the server, it restricts the user from adding any more than the maxlength number of characters to the field; any edits require you to shorten the field before adding more characters. The Firefox method probably is better from a security perspective, but there is some loss of context on the boards.

Posting Permissions

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