Create file with VBA

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
77
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi,
I create a file in the folder using the following code

VBA 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.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Do the check with

If objFSO.FileExists(your path) then …
 
Upvote 0
I could not use this code, can you help me more
Do the check with

If objFSO.FileExists(your path) then …
I could not use this code, can you help me more
 
Upvote 0
What is not working?
 
Upvote 0

Forum statistics

Threads
1,215,993
Messages
6,128,175
Members
449,429
Latest member
ianharper68

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top