我有一個自動化的Excel工作表,下面的腳本是功能的一部分。當我點擊工作表上的按鈕時,它將完全保存到路徑中,並通過電子郵件發送給下一個要查看的人員。VBA腳本保存文件以更正從一臺計算機但不是其他計算機的路徑
從另一臺計算機運行時,它不會將其保存到路徑中。請注意,我刪除了錯誤處理程序。在刪除它之前,它仍會通過電子郵件發送附件,但不會保存到其他計算機的路徑。
所有用戶都可以完全訪問該文件夾。代碼在工作表中。如果我把它放在一個模塊中,然後點擊按鈕,什麼都不會發生。
調試顯示模塊卡在saveas filepath部分。
任何幫助,非常感謝。
感謝
Private Sub CommandButton1_Click()
If WorksheetFunction.CountA(Range("$A27:$O32")) = 0 Then
MsgBox "Order has no accessories. Please submit to Distribution.", vbOKOnly
Exit Sub
End If
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Dim Attachment As String
Dim FName As String
Dim FPath As String
Dim Fmail As String
Dim FSection As String
Dim Ddate As String
FPath = "N:\Administration\Vehicle Orders"
FName = Sheets("Company Vehicle Order Form").Range("A13").Text
FSection = Sheets("Company Vehicle Order Form").Range("A25").Text
Ddate = Date
ActiveWorkbook.SaveAs Filename:= _
FPath & "\" & FName & " " & FSection & Ddate, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
TheAddress = "[email protected]"
Attachment = FPath & "\" & FName & " " & FSection & Ddate & ".xlsm"
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(TheAddress)
objOutlookRecip.Type = olTo
Set objAoutlookAttach = .Attachments.Add(Attachment)
.Subject = "Company Vehicle Order Form"
.Body = "Good day. Please review the attached Vehicle Order Form approve/ omit Accessories. If omitting, just delete the part and click on 'Submit to Distribution' button in the bottom BLUE section. " & _
vbCrLf & vbCrLf & "Thank you. "
.Importance = olImportanceHigh 'High importance
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
ActiveWorkbook.Close
End Sub
您還需要確保任何運行代碼的計算機都映射到驅動器。 –
如果您使用UNC路徑,則不需要映射的驅動器 - 是否「可以連接到路徑」? –
是@TimWilliams - >謝謝澄清。確保任何運行代碼的計算機都可以連接到路徑。 –