Abra o arquivo de texto e anexe o novo texto?

1

Eu tenho um texto que eu crio e depois quero anexar texto a ele. Mas estou recebendo um erro: chamada ou argumento de procedimento inválido.

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Dim filePath As String
filePath = "C:\myFile.txt"


If FileExists(filePath) = False Then
Set Fileout = fso.CreateTextFile(filePath, True, True)
Fileout.Write Msg
Fileout.Close
Else
Set Fileout = fso.OpenTextFile(filePath, ForAppending, TristateFalse) <<<<<== ERROR HERE
Fileout.Write Msg
Fileout.Close
End If

Function FileExists(strFullPath As String) As Boolean
'Check if a file or folder exists
If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileExists = True
End Function
    
por user590792 11.05.2016 / 16:17

1 resposta

2

Estou recebendo um erro: procedimento ou argumento inválido.

Set Fileout = fso.OpenTextFile(filePath, ForAppending, TristateFalse)

Você está passando TristateFalse como argumento 3. Deve ser o argumento 4.

Por favor, leia a documentação.

Description

Opens a specified file and returns a TextStream object that can be used to read from or append to the file.

Syntax

object.OpenTextFile(filename[, iomode[, create[, format]]])

The OpenTextFile method has these parts:

Part      Description
----      -----------
object    Required. Always the name of a FileSystemObject.
filename  Required. String expression that identifies the file to open.
iomode    Optional. Indicates input/output mode. Can be one of two constants, either ForReading or ForAppending.
create    Optional. Boolean value that indicates whether a new file can be created if the specified filename doesn't exist. The value is True if a new file is created; False if it isn't created. The default is False.
format    Optional. One of three Tristate values used to indicate the format of the opened file. If omitted, the file is opened as ASCII.

Source Método OpenTextFile

    
por 11.05.2016 / 16:25