0% found this document useful (0 votes)
44 views

Working With Files, Folders & Text Files: What You Learn

The document discusses various techniques for working with files and folders in Excel VBA: 1. It describes how to check if a file or folder exists using the DIR function. 2. It explains how to allow users to select files and folders using file dialog boxes and methods like GetOpenFileName and FileDialog. 3. It covers how to loop through files in a folder, create and export data to CSV files, and work with text files.

Uploaded by

nick gomez
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Working With Files, Folders & Text Files: What You Learn

The document discusses various techniques for working with files and folders in Excel VBA: 1. It describes how to check if a file or folder exists using the DIR function. 2. It explains how to allow users to select files and folders using file dialog boxes and methods like GetOpenFileName and FileDialog. 3. It covers how to loop through files in a folder, create and export data to CSV files, and work with text files.

Uploaded by

nick gomez
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 8

What you learn Working with Files, Folders & Text Files

Link Topic Covered What you Learn

DIR Check if File or Folder Exists ● Use the DIR function to check if a file or path exists
- DIR Function ● Create a new Folder (directory)
SelectFile User Selects a File - Allow the user to pick a file from Excel's file open dialog box.
GetOpenFileName Method The macro shows how to copy a specific range and import to
this workbook.
SelectFolder Loop Inside a Folder - Allow the user to pick a folder from Excel's file open dialog box.
FileDialog Property The macro shows how to loop through each file inside the
folder.

CSV Create CSV Files from Data How to save files as CSV by using Excel's SaveAs method
in Excel
Text Working with Text Files How to interact with Text files
Activity Export Data to a Text File How to create a text file with your own set delimiter
(and set your own (independent of the regional settings)
delimiter)
Check if File or Folder Exists - DIR Function

1. How to check if a file exists.


2. How to check if a path exists.
User Selects a File - GetOpenFileName Method

Note: In the sales reporting tool, you will learn how to use MultiSelect to import data from many files at once.

1. Allow the user to select an Excel file


2. Copy range A1:E20 of sheet 1 from the file selected and paste it starting from A10 below.
y files at once.
Loop Inside a Folder - FileDialog Property
Create CSV Files from Data in Excel

AT1030 84030 8050 120 130 6960


AT1030 84030 8050 104 530 5160
AT1030 84030 8050 105 130 1200
AT1030 84030 8050 107 740 3450
AT1030 84031 8040 104 920 10440
AT1030 84031 8040 107 810 3800
AT1030 84031 8040 110 550 30000
AT1030 88112 8040 110 530 28800
AT1030 88112 8040 119 690 39060
AT1030 88112 8040 120 150 8700
AT1030 88112 8040 116 810 4560
AT1030 88112 8040 111 640 11800
1030SE6 88112 8040 110 570 31800
1030SE6 88112 8040 109 260 7280
1030SE6 85442 8050 107 270 1350
1030SE6 85442 8050 103 670 7560
1030SE6 85442 8050 104 470 5280
1030SE6 85442 8050 120 530 29000
1030SE6 85442 8050 119 360 22320
1030SE6 85442 8050 115 840 4860
1030SE6 85442 8050 108 830 22400
1030SE6 88588 8040 120 500 27260
AT1030 84030 8050 120 130 6960
AT1030 84030 8050 104 530 5160
AT1030 84030 8050 105 130 1200
AT1030 84030 8050 107 740 3450
AT1030 84031 8040 104 920 10440
AT1030 84031 8040 107 810 3800
AT1030 84031 8040 110 550 30000
AT1030 88112 8040 110 530 28800
AT1030 88112 8040 119 690 39060
AT1030 88112 8040 120 150 8700
AT1030 88112 8040 116 810 4560
AT1030 88112 8040 111 640 11800
1030SE6 88112 8040 110 570 31800
1030SE6 88112 8040 109 260 7280
1030SE6 85442 8050 107 270 1350
1030SE6 85442 8050 103 670 7560
1030SE6 85442 8050 104 470 5280
1030SE6 85442 8050 120 530 29000
1030SE6 85442 8050 119 360 22320
1030SE6 85442 8050 115 840 4860
1030SE6 85442 8050 108 830 22400
1030SE6 88588 8040 120 500 27260
Working with Text Files
Export Data to a Text File (and set your own delimiter)
Export the following data to a text file that's saved in the same directory as this workbook.
● Delimiter should be a semicolon ";"
● File name should be: "ProjectActivity.csv"

AT1030 84030 8050 120 130 6960


AT1030 84030 8050 104 530 5160
AT1030 84030 8050 105 130 1200
AT1030 84030 8050 107 740 3450
AT1030 84031 8040 104 920 10440
AT1030 84031 8040 107 810 3800
AT1030 84031 8040 110 550 30000
AT1030 88112 8040 110 530 28800
AT1030 88112 8040 119 690 39060
AT1030 88112 8040 120 150 8700
AT1030 88112 8040 116 810 4560
AT1030 88112 8040 111 640 11800
1030SE6 88112 8040 110 570 31800
1030SE6 88112 8040 109 260 7280
1030SE6 85442 8050 107 270 1350
1030SE6 85442 8050 103 670 7560
1030SE6 85442 8050 104 470 5280
1030SE6 85442 8050 120 530 29000
1030SE6 85442 8050 119 360 22320
1030SE6 85442 8050 115 840 4860
1030SE6 85442 8050 108 830 22400
1030SE6 88588 8040 120 500 27260

Answer is in the completed workbook in "ProjectActivity" Module.

You might also like