Vbscript Windows脚本主机错误800A0046

Vbscript Windows脚本主机错误800A0046,vbscript,Vbscript,我在运行程序时收到以下错误: 脚本:C:My Folder\Tracking Macro.vbs 行:70 字符:1 错误:权限被拒绝 代码:800A0046 来源:Microsoft VBScript运行时错误 这是代码 ' Set constants for reading, writing, and appending files Const ForReading = 1, ForWriting = 2, ForAppending = 8 ' Sets up the object va

我在运行程序时收到以下错误:

脚本:C:My Folder\Tracking Macro.vbs
行:70
字符:1
错误:权限被拒绝
代码:800A0046
来源:Microsoft VBScript运行时错误

这是代码

' Set constants for reading, writing, and appending files
Const ForReading = 1, ForWriting = 2, ForAppending = 8

 ' Sets up the object variables.
 Dim objExcel, objFSO, objTextFile, objCSVFile

' Sets up the string variables.
Dim strTextFile, strHeadLine, strTextLine, strCSVFile

' Sets up the all the string variables for the program.
Dim Desktop, todaysDate, usageDate, myDay, myMonth, myYear

'This creates the required Objects
Set objExcel = CreateObject("Excel.application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Desktop = WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\" & "Desktop"

' Set date for date stamp in file name and sheet name
todaysDate = Date()

myMonth = Month(todaysDate)
If Len(myMonth)=1 Then myMonth="0" & myMonth

myDay = Day(todaysDate)
If Len(myDay)=1 Then myDay="0" & myDay

myYear = Right(Year(todaysDate), 2)

usageDate = myMonth & myDay & myYear

' Set up the origin and destination files
strTextFile = (Desktop & "\MacroTracker.txt")
strCSVFile = "C: My Folder\TrackingTesting" & usageDate & ".csv"
strHeadLine = "Macro Name,User ID,Ran At,Contracted Rate,BHVN,Set Number,Provider TIN,Billed Charge,Service Code"

Set objTextFile = objFSO.OpenTextFile(strTextFile)

' Read the entire origin file
Do Until objTextFile.AtEndOfStream
strTextLine = objTextFile.ReadLine
Loop

If (objFSO.FileExists(strCSVFile)) Then
' Create object for appending current TXT file to CSV file
Set objCSVFile = objFSO.OpenTextFile(strCSVFile, ForAppending, True)
' Write an append line of data to the CSV file
objCSVFile.WriteLine strTextLine
Else
' Create CSV file to write to with today's date
Set objCSVFile = objFSO.CreateTextFile(strCSVFile, True)
' Create object for appending current TXT file to CSV file
Set objCSVFile = objFSO.OpenTextFile(strCSVFile, ForAppending, True)
' Write initial header for the CSV file
objCSVFile.WriteLine strHeadLine
' Write an append line of data to the CSV file
objCSVFile.WriteLine strTextLine
End If

' Wait for file to be written to
Wscript.Sleep 600

' Delete origin file to prevent user tampering
objFSO.DeleteFile(strTextFile)
第70行是我删除文本文件的最后一行。根据我看到的每个帮助站点,这正是它应该如何键入的。我检查了文件的权限…我有完全的控制权,所以我应该能够删除它。它只是一个临时文件,而不是可以长时间存储信息的文件


我已经检查了Microsoft和所有其他帮助网站的错误代码,没有找到任何可以帮助我的解决方案。我希望有人可能遇到过类似的情况并找到了解决方案。

您的文件仍处于打开状态。您需要添加以下内容:

objTextFile.Close

在你试图删除它之前的某个地方。我会在您使用完该文件后立即将其放置。

您的文件仍处于打开状态。您需要添加以下内容:

objTextFile.Close

在你试图删除它之前的某个地方。我会在您使用完该文件后立即将其放置。

完美!!我甚至没有想过要把它合上,但如果我打开它来阅读它,这是有意义的。谢谢你的帮助。:)完美的我甚至没有想过要把它合上,但如果我打开它来阅读它,这是有意义的。谢谢你的帮助。:)