TopPicLogo TopPicText

Создание произвольного файла во временной папке Windows

По материалам: https://support.microsoft.com/

Sample Function to Generate a Random Temporary File Name
Create a module and type the following procedure:
Note that the name of the temporary file is displayed in the Debug window. The file contains the line "This is a Temp file." After you have verified that the file exists in your Temp folder, you can delete it.

Function MakeTempFileName(Extension As String) As String
      On Error Resume Next
      Dim Isfile As Integer, FHandle As Integer, Cntr As Integer
      Dim WinTemp As String, TF As String
         Isfile = False
         FHandle = FreeFile
      Do
         WinTemp = Environ("TEMP") & "\"
            For Cntr = 1 To 8
               WinTemp = WinTemp & Mid(LTrim(Str(CInt(Rnd * 10))), 1, 1)
            Next
            TF = Trim(WinTemp$) & "." & Extension

            Open TF For Output As #FHandle
            Debug.Print TF
            Print #FHandle, "This is a Temp file"
      Loop While Err > 0
      
      Close #FHandle
      MakeTempFileName = TF

End Function

Type the following line in the Debug window (or Immediate window in versions 1.x and 2.0), and then presss ENTER:
TempFileName$ = MakeTempFileName("TMP")

Назад ToTop
L.E. 13.09.2017
Рейтинг@Mail.ru