# Create file with VBA



## mmn1000 (Jan 4, 2023)

*Hi,*
*I create a file in the folder using the following code
*

```
[COLOR=rgb(85, 57, 130)][SIZE=5][B][/B][/SIZE][/COLOR]
Sub CreateTxtFile()
directory = "D:\Data\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile(directory & "F100.txt ")
End Sub
```

*
If the F100.txt file is available in the Data folder, write the name F100 in cell A1 of the sheet and write the word "available" in A2.
*
*If the F100.txt file is not available, create a file in the Data folder and write the word "F100.txt file created" in cell A2.*


----------



## JEC (Jan 4, 2023)

Do the check with 

If objFSO.FileExists(your path) then …


----------



## mmn1000 (Jan 4, 2023)

I could not use this code, can you help me more


JEC said:


> Do the check with
> 
> If objFSO.FileExists(your path) then …


I could not use this code, can you help me more


----------



## JEC (Jan 5, 2023)

What is not working?


----------



## mmn1000 (Jan 5, 2023)

If objFSO.FileExists(your path) then …


JEC said:


> What is not working?


----------

