0

I tried looking this over the Internet (also on SO) but did not find any solution.

I am looking for a way to get a filename of opened XML. My code opens like this:

Workbooks.OpenXML FileName:=pliczek, LoadOption:=xlXmlLoadImportToList

Variable pliczek is path of file and when code is executed new file is opened for example Sheet1. I want to know filename - I want to execute some code on it but no idea how to get this name.

Trying to activate next windows is risky if someone has more excel files opened.

lowak
  • 1,254
  • 2
  • 18
  • 38
  • http://stackoverflow.com/questions/1743328/how-to-extract-file-name-from-path – Karol Marian Słuszniak Oct 17 '14 at 13:57
  • Open() returns a reference to the workbook, so just assign that to a variable.... – Tim Williams Oct 17 '14 at 15:16
  • @KarolMarianSłuszniak there is no anwser to my question there. – lowak Oct 17 '14 at 17:22
  • @TimWilliams, `Open()` is not the same as `OpenXML`, especially when it goes with parameter `LoadOption:=xlXmlLoadImportToList`. As I wrote in my question, variable is path on HDD, so it's like `C:\1.xml`. When I open it with OpenXML it appears as `Sheet1` or other number at the end. I want to know programatically what name was given to a workbook so I reference to it. – lowak Oct 17 '14 at 17:23

2 Answers2

0

Code:

ActiveWorkbook.Name or if you need the full path ActiveWorkbook.Path

Community
  • 1
  • 1
Mr. Mascaro
  • 2,693
  • 1
  • 11
  • 18
0

This works for me

Sub Tester()

    Dim wb As Workbook
    Set wb = Workbooks.OpenXML(Filename:="C:\_Stuff\Test.xml", _
                               loadoption:=xlXmlLoadImportToList)

    Debug.Print wb.Name, wb.Sheets(1).Name

End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125