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 6339147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:35:30+00:00 2026-05-24T19:35:30+00:00

I’m trying to write a program that merge two or more .dat files in

  • 0

I’m trying to write a program that merge two or more .dat files in VBA excel. Basically, it first asks the user to select any number of files (more than 2). Then it “merges” the files based on the order that the user had selected them. By merge, I mean append or copy and paste one selected file into the previous selected file, and save as a brand new file. I’m stuck on on creating the new variables as Strings part, since I’m used to having the open prompt window pop up for just one file that need to be opened. Now it is conditional based on user’s selection at the message box of whether he wants another file merged with the previous. It keeps asking this until the user selects no or cancel. So each time the user selects yes there needs to be a new variable created to store the file name to be opened later. How do I go about this process? And also How do I open up all of these files at the same time once the user hits “no” to stop merging the files, and is there any clever way to append or Copy and Paste .dat files, I’ve tried Hex Editor: HxD, How do I manipulate the Hex Edit program with VBA?

   Sub Merge()
    Dim Response, Message As String
  Dim File1 As String 'Needs new variable created each time user selects "ok" on msgbox
   ChDir "C:\"

File1 = Application.GetOpenFilename(Title:="Select File to be Merged")
If File1 = "False" Then Exit Sub
Message = "Select Another File To be Merged With?"
Response = MsgBox(Message, vbQuestion + vbOKCancel, "Merge Files")
 If Response = vbOK Then
  'Loop-mechanism to create a new variable each time. HOW?

 Else
'Open .dat files and start the copy and pasting process HOW with Hex Editor?:I'm using a program called "HxD"
 End If
 End Sub

Thanks!

  • 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-05-24T19:35:30+00:00Added an answer on May 24, 2026 at 7:35 pm

    You can loop like this storing the names in an array of strings, then subsequently access each one individually for processing:

    Sub Merge()
        Dim File1      As String 'Needs new variable created each time user selects "ok" on msgbox
        Dim AllFiles() As String
        Dim count      As Long
    
        ChDir "C:\"
    
        ReDim AllFiles(0)
    
        Do
            Application.EnableCancelKey = xlDisabled
            File1 = Application.GetOpenFilename("DAT Files (*.dat),*.dat", 1, "Select File to be Merged")
            Application.EnableCancelKey = xlErrorHandler
    
            If (File1 = "False") Then Exit Do
            ReDim Preserve AllFiles(count)
            AllFiles(count) = File1
            count = (count + 1)
            If (MsgBox("Select Another File To be Merged With?", vbQuestion + vbOKCancel, "Merge Files") = vbCancel) Then Exit Do
        Loop
    
        If (count = 0) Then
            MsgBox "No selection"
            Exit Sub
        End If
    
        For count = 0 To UBound(AllFiles)
            MsgBox "User selected file name: " & AllFiles(count)
            '//boogy
        Next
    End Sub
    

    GetOpenFilename also support an MultiSelect argument however it only works in a single directory and the order of selected files is not guaranteed.

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

Sidebar

Related Questions

No related questions found

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.