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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:48:05+00:00 2026-06-16T00:48:05+00:00

I have an Excel worksheet from which I need to export range, A:1 to

  • 0

I have an Excel worksheet from which I need to export range, A:1 to last used cell in column A, to an xml file. How do you set the exported file name to be the same as the file I exported from?

Sub exportxmlfile()
Dim myrange As Range

Worksheets("xml").Activate
Set myrange = Range("A1:A20000")
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("C:\exports\2012\test.xml", True)
For Each c In myrange
a.WriteLine (c.Value)
Next c
a.Close
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-16T00:48:06+00:00Added an answer on June 16, 2026 at 12:48 am

    Use the Workbook.Name property to get the file name.

    FWIW, there are a few opportunities to improve your code

    Sub exportxmlfile()
       ' declare all your variables
        Dim myrange As Range
        Dim fs As Object
        Dim a As Object
        Dim dat As Variant
        Dim i As Long
    
        ' No need to activate sheet
        With Worksheets("xml")
            ' get the actual last used cell
            Set myrange = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp))
            ' copy range data to a variant array - looping over an array is faster
            dat = myrange.Value
            Set fs = CreateObject("Scripting.FileSystemObject")
            ' use the excel file name
            Set a = fs.CreateTextFile("C:\exports\2012\" & .Parent.Name & ".xml", True)
        End With
        For i = 1 To UBound(dat, 1)
            a.WriteLine dat(i, 1)
        Next
        a.Close
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a c# code which gets the (excel-2007) worksheets used range as follows
I am creating an Excel Worksheet from C# using Microsoft.Office.Interop.Excel, and I have not
I have an excel workbook which needs to query data from an HTTP server.
I have an excel file that i need to open and search it. This
I have a Excel file with multiple tabs. I have a worksheet with some
Inside an Excel worksheet, I would like to protect a cell (A1) from Editing
I have a WPF-mvvm application. I need to read an excel file..and create a
I have an Excel form which reads data from each row of an 80-row
I have an Excel Sheet with values going in each column from cells 2:21
I have a shared Excel worksheet (using .XLS due to compatibility issues), which I

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.