إرسال كائن إكسيل من الوصول مع سيندوبجيكت ، لا مرفق في البريد الإلكتروني

StackOverflow https://stackoverflow.com//questions/22018122

سؤال

عزيزي ستاكوفيرفلورز,

أحاول إرسال كائن إكسيل من أسيس مع سيندوبجيكت في فبا.

لدي الرمز الذي يجعل الرسم البياني:

    Dim oXL As Object        ' Excel application
    Dim oBook As Object      ' Excel workbook
    Dim oSheet As Object     ' Excel Worksheet
    Dim oChart As Object     ' Excel Chart


    Const cNumCols = 100      ' Number of points in each Series
    Const cNumRows = 26       ' Number of Series

    ReDim aTemp(1 To cNumRows, 1 To cNumCols)   

    Set oXL = CreateObject("Excel.application")
    Set oBook = oXL.Workbooks.Add
    Set oSheet = oBook.Worksheets.Item(1)

Dim rs01 As DAO.Recordset
Set rs01 = CurrentDb.OpenRecordset("SELECT * FROM qryWOperweekCombined")

Dim Teller As Integer
Teller = 0
Dim iRow As Integer
iRow = 1
Dim iCol As Integer
iCol = 5

With rs01
If .RecordCount > 0 Then
    .MoveLast
    TotRecords = .RecordCount
    .MoveFirst   
           For Teller = 1 To TotRecords
                 aTemp(iRow, 1) = !Week
                 aTemp(iRow, 2) = !Total
                 aTemp(iRow, 3) = !companyk
                 aTemp(iRow, 4) = !companyv
                .MoveNext
                iRow = iRow + 1
            Next Teller
    oSheet.Range("A1").Resize(cNumRows, cNumCols).Value = aTemp
End If
End With

    Set oChart = oSheet.ChartObjects.Add(200, 1, 745, 380).Chart

oChart.SetSourceData Source:=oSheet.Range("A1:D26")

    oXL.Visible = True

oChart.HasLegend = True
oChart.HasTitle = True

oChart.SeriesCollection(4).ApplyDataLabels
oChart.SeriesCollection(4).DataLabels.Format.TextFrame2.TextRange.Font.Size = 7
oChart.SeriesCollection(2).ApplyDataLabels
oChart.SeriesCollection(2).DataLabels.Format.TextFrame2.TextRange.Font.Size = 7
oChart.SeriesCollection(3).ApplyDataLabels
oChart.SeriesCollection(3).DataLabels.Format.TextFrame2.TextRange.Font.Size = 7

oSheet.Columns("A:A").ColumnWidth = 18.71

    oChart.SeriesCollection(1).Name = "=""Dates"""
    oChart.SeriesCollection(1).XValues = "=Sheet1!$A:$A"
    oChart.SeriesCollection(2).Name = "=""Total"""
    oChart.SeriesCollection(2).XValues = "=Sheet1!$B:$B"
    oChart.SeriesCollection(3).Name = "=""companyk"""
    oChart.SeriesCollection(3).XValues = "=Sheet1!$C:$C"
    oChart.SeriesCollection(4).Name = "=""companyv"""
    oChart.SeriesCollection(4).XValues = "=Sheet1!$D:$D"
    oChart.SeriesCollection(1).Delete
    oChart.SeriesCollection(1).Name = "=""Total"""
    oChart.SeriesCollection(1).XValues = "=Sheet1!$A:$A"

oChart.SeriesCollection(1).Interior.Color = vbBlue
oChart.SeriesCollection(2).Interior.Color = vbGreen
oChart.SeriesCollection(3).Interior.Color = vbRed

oChart.SeriesCollection(1).Trendlines.Add
oChart.SeriesCollection(2).Trendlines.Add
oChart.SeriesCollection(3).Trendlines.Add

    oChart.SeriesCollection(1).Trendlines.Add(Type:=xlMovingAvg, Period:= _
        2, Forward:=1, Backward:=0, DisplayEquation:=False, DisplayRSquared:= _
        False, Name:="Average").Select
    oChart.SeriesCollection(2).Trendlines.Add(Type:=xlMovingAvg, Period:= _
        2, Forward:=1, Backward:=0, DisplayEquation:=False, DisplayRSquared:= _
        False, Name:="Average").Select
    oChart.SeriesCollection(3).Trendlines.Add(Type:=xlMovingAvg, Period:= _
        2, Forward:=1, Backward:=0, DisplayEquation:=False, DisplayRSquared:= _
        False, Name:="Average").Select

With oChart.SeriesCollection(1).Trendlines(1).Border
 .ColorIndex = 5
 .Weight = xlThick
 .LineStyle = xlContinuous
 End With

 With oChart.SeriesCollection(1).Trendlines(2).Border
 .ColorIndex = 5
 .Weight = xlMedium
 .LineStyle = xlContinuous
 End With

With oChart.SeriesCollection(2).Trendlines(1).Border
 .ColorIndex = 4
 .Weight = xlThick
 .LineStyle = xlContinuous
 End With

 With oChart.SeriesCollection(2).Trendlines(2).Border
 .ColorIndex = 4
 .Weight = xlMedium
 .LineStyle = xlContinuous
 End With

With oChart.SeriesCollection(3).Trendlines(1).Border
 .ColorIndex = 3
 .Weight = xlThick
 .LineStyle = xlContinuous
 End With

 With oChart.SeriesCollection(3).Trendlines(2).Border
 .ColorIndex = 3
 .Weight = xlMedium
 .LineStyle = xlContinuous
 End With

 oChart.Legend.Position = xlBottom

 oChart.SetElement (msoElementChartTitleCenteredOverlay)

 oChart.HasTitle = True
 oChart.ChartTitle.Text = "Workorders per week - last 26 weeks"

   oSheet.Visible = True
   oXL.UserControl = True

ولدي رمز يرسل رسالة بريد إلكتروني:

Dim varName As Variant
Dim varCC As Variant
Dim varSubject As Variant
Dim varBody As Variant

varName = "name@server.com"
varCC = "name2@server2.com"

varSubject = "Hello"

varBody = "Text bla bla bla"

DoCmd.SendObject , oXL, acFormatXLS, varName, varCC, , varSubject, varBody, False, False

عندما أقوم بدمج هذه أحصل على رمز يرسل بريدا إلكترونيا ، ولكنه يصل بدون مرفق إكسيل (كما أنه لا يزال يفتح إكسيل ، لكنني سأكتشف ذلك لاحقا.

يتم الجمع بين هذه الرموز 2 في 1 الفرعية.

أي أفكار لماذا لا يرسل المرفق?أنا باستخدام اسم الكائن الخطأ (أوكسل) لأن أوشيت و أوبوك لا تعمل.أو يمكن أن يكون لها علاقة مع اكسل لا يزال يجري فتح?

هل كانت مفيدة؟

المحلول

SendObject هو لكائنات مس أسيس مثل استعلام أو نموذج أو تقرير.

يمكنك أيضا استخدامه لإرسال بريد إلكتروني بدون مرفق ، إذا تركت المعلمتين الأوليين فارغتين.

تقوم بإرسال كائن إكسيل في المعلمة الثانية التي يتم تجاهل الأمر.

بدلا من ذلك يجب عليك استخدام كائن أوتلوك لإرسال ملف إكسيل كمرفق عن طريق البريد, انظر سؤال ستاكوفيرفلو هنا.

بدلا من ذلك ، يمكنك استخدام ShellExecute

نصائح أخرى

شكرا جزيلا لمساعدتكم.رمز اختبار المثال الذي عمل بالنسبة لي هو:

giveacodicetagpre.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top