0

プログラムを実行すると、次のエラーが表示されます。

スクリプト: 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 および他のすべてのヘルプ サイトでエラー コードを確認しましたが、解決策が見つかりませんでした。誰かが同様のインスタンスに遭遇し、解決策を見つけたことを願っています.

4

1 に答える 1