VBA Export XmlMap and navigate where to save as.

Addictions

Board Regular
Joined
May 27, 2018
Messages
60
Office Version
  1. 365
Hello,

I am trying to figure out how to export XmlMap with a prompt to navigate where to save as.
Currently I have a code which exports XmlMap but to the file path and I would like to navigate where to save it as.
Can you help please?.

VBA Code:
Sub ExportAsXMLData()
 Dim objMapToExport As XmlMap
 
 Set objMapToExport = ActiveWorkbook.XmlMaps("Customer")
 
 If objMapToExport.IsExportable Then
 
 ActiveWorkbook.SaveAsXMLData "Customer Data.xml", objMapToExport
 Else
 MsgBox "Cannot use " & objMapToExport.Name & _
 "to export the contents of the worksheet to XML data."
 End If
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I can only find a way to add a hard path in to the code. I am sure there must be a way for a prompt where to save it.
 
Upvote 0
Replace the Save line with:
VBA Code:
        Dim XMLfullName As Variant
        XMLfullName = Application.GetSaveAsFilename(InitialFileName:="Customer Data.xml", FileFilter:="XML Files (*.xml), *.xml", Title:="Save XML Data")
        
        If XMLfullName <> False Then
            ActiveWorkbook.SaveAsXMLData XMLfullName, objMapToExport
            MsgBox "Saved " & XMLfullName
        Else
            MsgBox "User cancelled - not saved"
        End If
 
Upvote 0
Haha, happens to all of us.

Works amazing! You are a genius. Thanks for the help. Much appreciated!
 
Upvote 0

Forum statistics

Threads
1,215,403
Messages
6,124,710
Members
449,182
Latest member
mrlanc20

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top