• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

How can I force VBA for word to Launch an .xml file only in Excel?

I am in VBA for word editor.

How can I specify that I want to Launch an external .xml file only in Excel from VBA in Word?

In windows, the .xml is not associated to open with excel. Which command parameters do I use?

Thanks in advance.
Full points given for this.

  • 3
  • 2
2 Solutions
Ryan ChongCommented:
If your xml file is set properly, you can try like:

Shell "Excel D:\yourfolder\yourfile.xml"
If you need to work on the workbook in your VBA, you will need to capture the objects.
Sub OpenForExcel()
    Dim xlApp As Excel.Application
    Dim xlWbk As Excel.Workbook
    Dim xlWks As Excel.Worksheet
    Dim strFileName As String
    strFileName = "C:\MyFolder\MyFile.xlm"
    On Error Resume Next
    Set xlApp = GetObject(, "Excel.Application")
    On Error GoTo 0
    If xlApp Is Nothing Then
        Set xlApp = CreateObject("Excel.Application")
    End If
    xlApp.Visible = True
    Set xlWbk = xlApp.Workbooks.Open(strFileName)
    Set xlWks = xlWbk.Sheets(1)
End Sub

Open in new window

New_AlexAuthor Commented:
Thanks GrahamSkan: but I need just a simple line just to open the .xml file into excel.

ryancys method looks fine but for some reason it does not work
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

New_AlexAuthor Commented:
I think the problem is that I have spaces in the Folder`s Name.

Shell can not handle spaces....

Any ideas?


Shell "Excel ""D:\your folder\yourfile.xml"""
New_AlexAuthor Commented:
Thanks Guys.

This has to be a share.

Take care
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now