设置我的文件路径以引用VBA脚本中的OneDrive目录

时间:2018-05-17 16:44:53

标签: excel-vba onedrive vba excel

我正在尝试为管理员自动发送佣金表。当我将文件本地移动到我的C:时,编码工作正常,但当我将其更改为我的OneDrive帐户的本地路径时,脚本编写失败。最终,我希望能够引用OneDrive路径,无论谁运行报告。这是我的脚本:

Sub Send_email_fromexcel()
Dim Edress As String
Dim Subject As String
Dim Message As String
Dim Filename As String
Dim outlookapp As Object
Dim myAttachments As Object
Dim path As String
Dim lastrow As Integer
Dim Attachment As String
Dim x As Integer

x = 6
y = 2
Z = 3

Do While Sheets("Austin").Cells(x, 1) <> ""

Set outlookapp = CreateObject("Outlook.Application")
Set outlookmailitem = outlookapp.createitem(0)
Set myAttachments = outlookmailitem.Attachments

path = Sheets("Austin").Range("B2")
Edress = Sheets("Austin").Cells(x, 1)
Subject = Sheets("Austin").Cells(x, 2)
Filename = Sheets("Austin").Cells(x, 3)
Attachment = path + Filename

outlookmailitem.To = Edress
outlookmailitem.cc = ""
outlookmailitem.bcc = ""
outlookmailitem.Subject = Subject
outlookmailitem.body = Sheets("Austin").Cells(Z, 2)

myAttachments.Add (Attachment)
outlookmailitem.display
outlookmailitem.send

lastrow = lastrow + 1
Edress = ""

x = x + 1

Loop

Set outlookapp = Nothing
Set outlookmailitem = Nothing


End Sub

0 个答案:

没有答案