• Capture selected Background Pattern Shading (Word

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Capture selected Background Pattern Shading (Word

    Author
    Topic
    #416947

    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

    Viewing 1 reply thread
    Author
    Replies
    • #933994

      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.

      • #933995

        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

        • #934003

          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

          • #934006

            Genius…genius….

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

            Thank you.

    • #934548

      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.

      • #934581

        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

        • #934592

          Some browsers cut off the subject when you post.

          • #934772

            I used Firefox for this thread.

            • #934775

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

            • #934960

              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.

    Viewing 1 reply thread
    Reply To: Capture selected Background Pattern Shading (Word

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: