0

このサイトから Excel のモジュール/マクロを取得しました: [Excel コンテンツの電子メールを送信するマクロ][1] マクロは機能しますが、各セル内の大量のデータに対してセルが小さすぎることを除きます。セル内のデータに応じてセルの幅を調整するコード。セルは、データ量の点で異なります。ありがとう!

Sub Send_Row()
      ' Don't forget to copy the function RangetoHTML in the module.
      ' Working in Office 2000-2010
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim rng As Range
Dim Ash As Worksheet

Set Ash = ActiveSheet
On Error GoTo cleanup
Set OutApp = CreateObject("Outlook.Application")

With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With

For Each cell In Ash.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
    If cell.Value Like "?*@?*.?*" And LCase(cell.Offset(0, 1).Value) = "yes" Then

        Ash.Range("A1:AE100").AutoFilter Field:=2, Criteria1:=cell.Value

        With Ash.AutoFilter.Range
            On Error Resume Next
            Set rng = .SpecialCells(xlCellTypeVisible)
            On Error GoTo 0
        End With

        Set OutMail = OutApp.CreateItem(0)

        On Error Resume Next
        With OutMail
            .To = cell.Value
            .Subject = "CSI"
            .HTMLBody = RangetoHTML(rng)
            .Display  'Or use Send
        End With
        On Error GoTo 0

        Set OutMail = Nothing
        Ash.AutoFilterMode = False
    End If
Next cell

       cleanup:
Set OutApp = Nothing
With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With
      End Sub
4

1 に答える 1

0

私が使う

Excel.Rows.AutoFit

Excel.Columns.AutoFit

ワークシートのセルがコンテンツに最適な高さと幅に自動的に調整されるようにします。

この 2 行のコードは、コード内の任意の場所で呼び出すことができますが、私は電子メールを作成する直前に呼び出します。

別の方法として、手動で行いたい場合は、次のショートカット キーを使用します。

Alt+ O+ C+ A- 列の自動調整
Alt+ O+ R+ A- 行の自動調整

于 2012-06-08T16:16:54.040 に答える