Create file with VBA

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
76
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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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,212
Messages
6,123,655
Members
449,113
Latest member
Hochanz

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