Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please code in Microsoft Excel Visual Basic for Applications (VBA). Objective: Import and parse text from a file. - Write a sub that imports a

Please code in Microsoft Excel Visual Basic for Applications (VBA).

Objective: Import and parse text from a file.

- Write a sub that imports a single line of text from the text file M6_Ex1_Sample_txt.

- Use GetOpenFilename method to navigate to the file and obtain the file name.

- Do not open as a workbook (don't use Filename.Open); Instead open for import.

- Use SPLIT to parse the file. View the file first to determine the delimiter.

Hint: Did you know can use a multi-character string as a delimiter? Hint: Check the length of your strings on the output sheet. If they look long, check for spaces

- Build a message box that displays all of the words in column.

- Count the number of words and the number of words with greater than 5 characters and report those results in a message box.

- Details are important on this problem. Be sure to check your results.

Contents of M6_Ex1_SampleText.txt file:

Zags, Golden Eagles, Hawks, Peacocks, Greyhounds, Golden Griffens, Dons, Musketeers

----------------------------------------------------------------------------------------------------------------------------------

Option Explicit ' ******** DSS 620 Template ---- Created by John A. Michl jmichl@sju.edu ******** ' ** ' ** Module 6 Exercise 1 ' ** Template Revision: 6/13/2018 by John A. Michl ' ** Student comments should use apostrophe only ' ** ' ** Assignment modified by STUDENT NAME on DATE ' ** ' ******************************************************************************

Sub ImportTextFile()

Dim fileName As Variant ' array will hold the file name or names to import Dim i As Integer ' counter for loops Dim nLargeWords As Integer ' counter for words longer than 5 characters Dim dataLine As String ' string to hold a single line of text from file Dim lineCount As Integer Dim arrWords() As String ' array that will hold the contents of the text file Dim msg As String ' string for building the first message box With Range("Output_lbl") Range(.Offset(1, 1), .Offset(100, 2)).ClearContents End With '<<<<>>> '============Navigate to file location and get filename of text file '============Import file into temp string variable then parse into an array

'===========create and display the message boxes ' and output array contents and word lengths to the output sheet

End Sub

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions