Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8138587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:32:19+00:00 2026-06-06T11:32:19+00:00

I have been attempting to write a VBA Script that can parse out other

  • 0

I have been attempting to write a VBA Script that can parse out other files for specific data that I can then input into the currently opened Excel Workbook. The files are all Tab Deliminated and are found in a different directory than the currently opened workbook. The code below worked until I restarted my computer, and now I always get a “1004 Runtime Error.” This error always occurs when the code hits the “select.TextToColumns” line of the DeliminateCSV subroutine. The error occurs because the program is selecting empty cells. I believe the program is selecting the currently open workbook which is currently empty. I believed maybe my CSV variable in ParseSummaryReport was opening the wrong workbook, but I watched it in Debug mode and it seemed to have the correct filepath to open. Any ideas whats going on?

Option Explicit
    Sub PopulateSpreadSheet()

    Dim fso             As Object
    Dim fPath As String
    Dim fsoFolder As Scripting.folder
    Dim startingFolder As Scripting.folder
    Dim iNumFiles As Integer

        Set fso = CreateObject("Scripting.FileSystemObject")

        'Get path of current workbook
        fPath = ActiveWorkbook.Path
        Set fsoFolder = fso.GetFolder(fPath)

        'Move up one directory
        Set startingFolder = fsoFolder.ParentFolder

        iNumFiles = 0

        Call RecursiveFileCheck(startingFolder, iNumFiles)

    End Sub

    Sub ParseSummaryReport(ByRef i As Integer, fileName As String)
    Dim CSV As Workbook
    Dim Excel As Excel.Application

    'Data From CSV To Put In Tracking
    Dim ES_Number As String
    Dim custodian As String
    Dim EDoc_Size As Double
    Dim Email_Size As Double

    Set Excel = New Excel.Application

    'Set CSV = Excel.Workbooks.Open(fileName)
    Set CSV = Excel.Workbooks.Open(fileName, , , , , , , , "    ")



    'Deliminate the CSV File
    'Call DeliminateCSV(CSV)


    Call CSV.Close(False)

    End Sub

    Sub RecursiveFileCheck(ByRef folder As Scripting.folder, ByRef iNumFiles As Integer)
    Dim nextFolder As Scripting.folder
    Dim fileName As String
    Dim nextFile, files, subFolders

    Set files = folder.files
    Set subFolders = folder.subFolders

    'Search through all the files in this folder
    For Each nextFile In files

        'Check if this is one of the files we want
        If nextFile Like "*_SummaryReport.csv" Then

            'Summary Report Found, Parse It
            fileName = nextFile
            Call ParseSummaryReport(iNumFiles, fileName)
        End If

    Next nextFile

    'Search through all the subfolders recursively
    For Each nextFolder In subFolders
        Call RecursiveFileCheck(nextFolder, iNumFiles)
    Next nextFolder

    End Sub

    Sub DeliminateCSV(ByRef wrkBook As Workbook)
        With wrkBook
            Columns("A:A").Select
            Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
                TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
                Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
                :=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
        End With
    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:32:20+00:00Added an answer on June 6, 2026 at 11:32 am

    When you use

    With wrkBook
    ...
    End with
    

    then you should add a “.” in front of any properties or methods belonging to that workbook

    With wrkBook
        Columns("A:A").Select             
        Selection.TextToColumns Destination:=Range("A1")...
    End With
    

    should be

    With wrkBook
        .Columns("A:A").Select             
        Selection.TextToColumns Destination:=.Range("A1")...
    End With
    

    You don’t need to select though:

    .Columns("A:A").TextToColumns Destination:=.Range("A1")...
    

    will also work

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been attempting to have a object that I can use across multiple
I have been attempting to write a program that will determine if a number
Morning Everyone, I've been attempting to write an application that does some GETs from
I have been attempting to write a reusable generic method for lookups on a
For the past few days I have been attempting to write my own shell
I am attempting to write a user script that makes a cross domain AJAX
I have been attempting to write some routines to read RSS and ATOM feeds
I've been attempting to write a Lisp macro that would perfom the equivalent of
I'm attempting to build a method call from strings that have been passed into
I have been attempting to get log4net logging in my asp.net web application with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.