excel 为什么“保存为”显示它正在查找windows系统文件夹中的文件,而不是我的实际文件路径?

6qftjkof  于 2023-01-06  发布在  Windows
关注(0)|答案(1)|浏览(317)

它以前是工作的,保存一个密码保护的文件到一个电子邮件附件。现在突然它说它正在寻找一个文件在系统文件夹,而路径是一个简单的文件夹在我的本地文档

Sub FY23_PWProtectCompFile()

Dim i As Integer
Dim chapterComp As Workbook
Dim emailList As Worksheet
Dim rng As Range
Dim pw As String
Dim chapter As String
Dim rows As Integer
Dim subj As String
Dim attachment As String
Dim chapterFile As Workbook

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

Set chapterComp = Workbooks.Open("I:\Calendar 2023\2023 Budget\2023 Misc. Budget Info\blahblah.xlsm")
Set emailList = chapterComp.Sheets("EmailList")
Set rng = emailList.Range("B1:Z1000")

Workbooks.Open ("I:\Calendar 2023\2023 Budget\2023 Misc. Budget Info\blahblah.xlsm")
emailList.Activate

rows = Range("B2").End(xlDown).Row

For i = 2 To rows
    chapter = Range("B" & i).Value
    email = Range("H" & i).Value
    pw = Range("I" & i).Value
    
    Set chapterFile = Workbooks.Open("C:\Users\blah\Documents\Chapters\" & chapter & ".xlsx")
    Workbooks.Open ("C:\Users\blah\Documents\Chapters\" & chapter & ".xlsx")
    
    
    chapterFile.SaveAs Password:=pw
    
        outlookmailitem.To = email
        outlookmailitem.cc = ""
        outlookmailitem.bcc = ""
        outlookmailitem.Subject = chapter & " Compensation"
        outlookmailitem.body = "A copy of your compensation budget is attached!"
           
        attachment = chapterFile.Name
            
        myAttachments.Add (attachment)
        outlookmailitem.display
        'outlookmailitem.send

Next i

End Sub
qpgpyjmq

qpgpyjmq1#

我重新启动了我的机器,这个程序照常工作。如果您收到一个运行时错误,提到涉及outlook时的临时位置,您可以尝试重新启动您的机器。

相关问题