I have an XML Map that is mapped to a Sheet in Excel.
I always exported it through Developer - Export, wrote the filename, clicked through the folders and exported it.
I'm trying to make my life a bit easier and wanted to create a button on the Sheet, that would trigger the Export dialog window with a suggested file name and file path from the cell A24, since the name of the folders in my documents are always the same as the value in A24.
I came very close to making this happen by writing this code:
This brings up the Export dialog windows with the suggested file name and file path correctly and when I hit Save, it actually saves.
The problem is when I decide to Export the XML to a different folder than the one suggested, it obviously saves to the suggested file path anyway, because of
Now i know there is a lot of this on the internet and i've read through most of it and tried bunch of different stuff, but always seem to end up in a dead end.
How and what do i have to change/add to have the suggested file name and path, but if the folder does not exist or the user decides to save it elsewhere, it actually does.
Any help is appreciated!
I always exported it through Developer - Export, wrote the filename, clicked through the folders and exported it.
I'm trying to make my life a bit easier and wanted to create a button on the Sheet, that would trigger the Export dialog window with a suggested file name and file path from the cell A24, since the name of the folders in my documents are always the same as the value in A24.
I came very close to making this happen by writing this code:
VBA Code:
Public Sub ExportToXML()
Dim strFileName As String
Dim FilePath As String
Dim objMapToExport As Variant
Filepath = "C:\Users\admin\Desktop\Documents\" & Range("A24") & "\" & Range("A24") & ".xml"
strFileName = Application.GetSaveAsFilename(InitialFileName:=Filepath, FileFilter:="XML Files (*.xml), *.xml", Title:="Save FileAs...")
If strFileName <> False Then
ActiveWorkbook.SaveAsXMLData Filepath, objMapToExport
MsgBox "Saved " & Filepath
Else
MsgBox "User cancelled - not saved"
End If
End Sub
This brings up the Export dialog windows with the suggested file name and file path correctly and when I hit Save, it actually saves.
The problem is when I decide to Export the XML to a different folder than the one suggested, it obviously saves to the suggested file path anyway, because of
Code:
ActiveWorkbook.SaveAsXMLData Filepath, objMapToExport
Now i know there is a lot of this on the internet and i've read through most of it and tried bunch of different stuff, but always seem to end up in a dead end.
How and what do i have to change/add to have the suggested file name and path, but if the folder does not exist or the user decides to save it elsewhere, it actually does.
Any help is appreciated!