ПЕРЕДАЧА ПАРАМЕТРОВ ПРОЦЕДУРЕ EXCEL - VB

Узнай цену своей работы

Формулировка задачи:

Как передать процедуре диапазон ячеек
и как им воспользоваться ?
Обращение к процедуре имеет вид:

Ниже приведен код процедуры,
снимающий линии – БОРДЮРЫ вокруг ячеек
(обрамление, если так можно назвать)

СПАСИБО

Решение задачи: «ПЕРЕДАЧА ПАРАМЕТРОВ ПРОЦЕДУРЕ EXCEL»

textual
Листинг программы
<font color="blue">Public</font> <font color="blue">Enum</font> XBorderWeight
    xDefault = -<font color="darkblue"><b>1</b></font>
    xNone = -<font color="darkblue"><b>4142</b></font>
    xHairline = <font color="darkblue"><b>1</b></font>
    xMedium = -<font color="darkblue"><b>4138</b></font>
    xThick = <font color="darkblue"><b>4</b></font>
    xThin = <font color="darkblue"><b>2</b></font>
<font color="blue">End</font> <font color="blue">Enum</font>
<font color="blue">Public</font> <font color="blue">Enum</font> XBorderPosition
    xEdgeLeft = <font color="darkblue"><b>7</b></font>
    xEdgeTop = <font color="darkblue"><b>8</b></font>
    xEdgeBottom = <font color="darkblue"><b>9</b></font>
    xEdgeRight = <font color="darkblue"><b>10</b></font>
    xInsideVertical = <font color="darkblue"><b>11</b></font>
    xInsideHorizontal = <font color="darkblue"><b>12</b></font>
<font color="blue">End</font> <font color="blue">Enum</font>

<font color="blue">Public</font> <font color="blue">Sub</font> Bord(<font color="blue">ByVal</font> rng <font color="blue">As</font> Excel.Range, _
                Optional <font color="blue">ByVal</font> linStyle <font color="blue">As</font> Excel.XlLineStyle = xlContinuous, _
                Optional <font color="blue">ByVal</font> el <font color="blue">As</font> XBorderWeight = xDefault, _
                Optional <font color="blue">ByVal</font> et <font color="blue">As</font> XBorderWeight = xDefault, _
                Optional <font color="blue">ByVal</font> eb <font color="blue">As</font> XBorderWeight = xDefault, _
                Optional <font color="blue">ByVal</font> er <font color="blue">As</font> XBorderWeight = xDefault, _
                Optional <font color="blue">ByVal</font> iv <font color="blue">As</font> XBorderWeight = xDefault, _
                Optional <font color="blue">ByVal</font> ih <font color="blue">As</font> XBorderWeight = xDefault)

    <font color="blue">Dim</font> vTmpArea <font color="blue">As</font> Excel.Range
<font color="blue">On</font> <font color="blue">Error</font> <font color="blue">GoTo</font> ErrH
    
    <font color="blue">If</font> <font color="blue">Not</font> rng <font color="blue">Is</font> <font color="blue">Nothing</font> <font color="blue">Then</font>
        <font color="blue">With</font> rng
            <font color="blue">For</font> <font color="blue">Each</font> vTmpArea <font color="blue">In</font> .Areas
                <font color="blue">With</font> vTmpArea
                    <font color="blue">If</font> el <> xDefault <font color="blue">Then</font>
                        <font color="blue">With</font> .Borders(xEdgeLeft)
                            <font color="blue">If</font> el = xNone <font color="blue">Then</font>
                                .LineStyle = xlNone
                            <font color="blue">Else</font>
                                .LineStyle = linStyle
                                .Weight = el
                                .ColorIndex = xlAutomatic
                            <font color="blue">End</font> <font color="blue">If</font>
                        <font color="blue">End</font> <font color="blue">With</font>
                    <font color="blue">End</font> <font color="blue">If</font>
                    <font color="blue">If</font> et <> xDefault <font color="blue">Then</font>
                        <font color="blue">With</font> .Borders(xEdgeTop)
                            <font color="blue">If</font> et = xNone <font color="blue">Then</font>
                                .LineStyle = xlNone
                            <font color="blue">Else</font>
                                .LineStyle = linStyle
                                .Weight = et
                                .ColorIndex = xlAutomatic
                            <font color="blue">End</font> <font color="blue">If</font>
                        <font color="blue">End</font> <font color="blue">With</font>
                    <font color="blue">End</font> <font color="blue">If</font>
                    <font color="blue">If</font> eb <> xDefault <font color="blue">Then</font>
                        <font color="blue">With</font> .Borders(xEdgeBottom)
                            <font color="blue">If</font> eb = xNone <font color="blue">Then</font>
                                .LineStyle = xlNone
                            <font color="blue">Else</font>
                                .LineStyle = linStyle
                                .Weight = eb
                                .ColorIndex = xlAutomatic
                            <font color="blue">End</font> <font color="blue">If</font>
                        <font color="blue">End</font> <font color="blue">With</font>
                    <font color="blue">End</font> <font color="blue">If</font>
                    <font color="blue">If</font> er <> xDefault <font color="blue">Then</font>
                        <font color="blue">With</font> .Borders(xEdgeRight)
                            <font color="blue">If</font> er = xNone <font color="blue">Then</font>
                                .LineStyle = xlNone
                            <font color="blue">Else</font>
                                .LineStyle = linStyle
                                .Weight = er
                                .ColorIndex = xlAutomatic
                            <font color="blue">End</font> <font color="blue">If</font>
                        <font color="blue">End</font> <font color="blue">With</font>
                    <font color="blue">End</font> <font color="blue">If</font>
                    <font color="blue">If</font> iv <> xDefault <font color="blue">Then</font>
                        <font color="blue">If</font> .Columns.Count > <font color="darkblue"><b>1</b></font> <font color="blue">Then</font>
                            <font color="blue">With</font> .Borders(xInsideVertical)
                                <font color="blue">If</font> iv = xNone <font color="blue">Then</font>
                                    .LineStyle = xlNone
                                <font color="blue">Else</font>
                                    .LineStyle = linStyle
                                    .Weight = iv
                                    .ColorIndex = xlAutomatic
                                <font color="blue">End</font> <font color="blue">If</font>
                            <font color="blue">End</font> <font color="blue">With</font>
                        <font color="blue">End</font> <font color="blue">If</font>
                    <font color="blue">End</font> <font color="blue">If</font>
                    <font color="blue">If</font> ih <> xDefault <font color="blue">Then</font>
                        <font color="blue">If</font> .Rows.Count > <font color="darkblue"><b>1</b></font> <font color="blue">Then</font>
                            <font color="blue">With</font> .Borders(xInsideHorizontal)
                                <font color="blue">If</font> ih = xNone <font color="blue">Then</font>
                                    .LineStyle = xlNone
                                <font color="blue">Else</font>
                                    .LineStyle = linStyle
                                    .Weight = ih
                                    .ColorIndex = xlAutomatic
                                <font color="blue">End</font> <font color="blue">If</font>
                            <font color="blue">End</font> <font color="blue">With</font>
                        <font color="blue">End</font> <font color="blue">If</font>
                    <font color="blue">End</font> <font color="blue">If</font>
                <font color="blue">End</font> <font color="blue">With</font>
            <font color="blue">Next</font> vTmpArea
        <font color="blue">End</font> <font color="blue">With</font>
    <font color="blue">End</font> <font color="blue">If</font>
<font color="blue">Exit</font> <font color="blue">Sub</font>
ErrH:
    Err.Raise Err.Number, <font color="teal">"Bord"</font>, Err.Description
<font color="blue">End</font> <font color="blue">Sub</font>

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 4 из 5