繁体   English   中英

Windows脚本主机错误800A0046

[英]Windows script host error 800A0046

运行程序时出现以下错误:

脚本:C:我的文件夹\\跟踪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

在尝试删除它之前。 使用完文件后,我会说对了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM