Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»How to convert a CSV file to an Excel file

    How to convert a CSV file to an Excel file

    May 17, 2024

    Converting CSV to Excel streamlines data manipulation and analysis, bridging the simplicity of CSV’s plain text structure with Excel’s powerful spreadsheet functionalities. This conversion ensures a seamless transition from comma-separated records to organized rows and columns, enhancing data accessibility and interpretation. Whether for data analysis, visualization, or collaboration, Excel’s versatile format accommodates diverse needs, offering features like formulas, charts, and conditional formatting.

    Converted the CSV file with leading zero’s unchanged when changed to an Excel file.
    Multiple CSV files are automatically converted to Excel files using code built in a loop.

    By converting multiple CSV files to an Excel file using VBA code.

    VBA CODE:

    Sub Csv_to_Excel()
    ‘
    ‘ Csv_to_Excel
    Dim Pathname As String
    Dim Filename As String
    Dim WOextn As String
    Dim Nam As String

    Pathname = “<Specify the Souce Path>”
    Filename = Dir(Pathname)

    Do While Filename <> “”
    WOextn = Left(Filename, InStr(1, Filename, “.”) – 1)
    Nam = Pathname & “” & Filename
    Debug.Print Nam
    Workbooks.Add
    ActiveWorkbook.Queries.Add Name:=WOextn, Formula:= _
    “let” & Chr(13) & “” & Chr(10) & ” Source = Csv.Document(File.Contents(” & Chr(34) & Nam & Chr(34) & “),[Delimiter=””,””, Columns=25, Encoding=1252, QuoteStyle=QuoteStyle.None]),” & Chr(13) & “” & Chr(10) & ” #””Promoted Headers”” = Table.PromoteHeaders(Source, [PromoteAllScalars=true])” & Chr(13) & “” & Chr(10) & “in” & Chr(13) & “” & Chr(10) & ” #””Promoted Headers”””
    ActiveWorkbook.Worksheets.Add
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
    “OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=” & WOextn & “;Extended Properties=””””” _
    , Destination:=Range(“$A$1”)).QueryTable
    .CommandType = xlCmdSql
    .CommandText = Array(“SELECT * FROM [” & WOextn & “]”)
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .PreserveColumnInfo = True
    Debug.Print WOextn
    .ListObject.DisplayName = WOextn
    .Refresh BackgroundQuery:=False
    End With
    Application.CommandBars(“Queries and Connections”).Visible = False
    Range(“C8”).Select
    ActiveSheet.Name = WOextn
    ActiveWorkbook.SaveAs Filename:=”<Specify the target path>” & WOextn & “.xlsx”
    ActiveWorkbook.Close
    Filename = Dir()
    Loop
    End Sub

    Step By Step Procedure to Run the VBA code:

    Step 1: Open a new Excel sheet.

    Step 2: Go to the Developer tab ribbon option.

    Step 3: Select the Visual Basic option in the Developer Tab.

    Step 4: Selecting the Visual Basic option opens a new window.

    Step 5: On the Project tab, right-click the VBA project. Click Module after choosing the Insert option.

    Step 6: The module option will show in the Project tab under the VBA Project, and the right-side code space will open.

    Step 7: Paste the VBA code in the code space.

    Step 8: Select Run or press F5 to run the code from here manually.

    All of the CSV files that are in the designated folder have been successfully converted into Excel files and loaded into the target folder once the VBA code has been executed.

     

     

     

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleDynamic lookup in Talend
    Next Article Eliminating Data Duplication: A Guide to Duplicate Rules in Salesforce

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-40906 – MongoDB BSON Serialization BSON::XS Multiple Vulnerabilities

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Top 15+ GPU Server Hosting Providers in 2025

    Development

    Edge’s Game Assist feature is finally launching for everyone, thanks to Edge Stable 132

    Operating Systems

    SpaceX Data Breach Back From the Dead: Hunters International Posts Alleged Stolen Information

    Development

    Bill Gates shares his original Altair BASIC source code for Microsoft’s 50th anniversary — “The coolest code I’ve ever written”

    News & Updates
    GetResponse

    Highlights

    Developer Spotlight: Mario Sanchez Maselli

    January 24, 2025

    Meet Mario, developer & co-founder of Non-Linear Studio. Specializing in interactive design, animation, 3D, WebGL,…

    Agents bring the role of AI in development from reactive to proactive

    April 10, 2025

    CVE-2025-47681 – Ability, Inc Web Accessibility with Max Access CSRF

    May 7, 2025

    TCL’s new 5G phone won’t strain your eyes or your wallet, and it’s coming to the US

    January 6, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.