+ Reply to Thread
Results 1 to 3 of 3

VBA: Saving a Exported XML with a predefined file name with a time stamp

Hybrid View

Pawtucket VBA: Saving a Exported XML... 08-05-2015, 09:38 AM
ranman256 Re: VBA: Saving a Exported... 08-06-2015, 10:46 AM
Pawtucket Re: VBA: Saving a Exported... 08-06-2015, 10:46 AM
  1. #1
    Registered User
    Join Date
    08-05-2015
    Location
    Hartford, CT
    MS-Off Ver
    MS Office 2010
    Posts
    2

    VBA: Saving a Exported XML with a predefined file name with a time stamp

    So I can get this to work where it exports the XML:

    Sub ExportXML()
    '
    ' ExportXML Macro
    '
    Application.CommandBars.ExecuteMso ("XmlExport")
    '
    End Sub
    And this works, to save the actual Excel doc with a specific predefined place ("C:....") and name (Value from Cell A10) with a time stamp:

    Sub SaveMyWorkbook()
        Dim vFile As Variant
        Dim sCurrDir As String
        Dim sName As Variant
        Dim strdate As String
    
        sName = [A10] 'value from A1
        strdate = Format(Now, "dd-mm-yy h-mm-ss")
        ' save current directory, and change to desired starting directory
        sCurrDir = CurDir
        ChDrive "C:\....."
        ChDir "C:\....."
    
        vFile = Application.GetSaveAsFilename(InitialFileName:=sName & strdate, _
            fileFilter:="Excel files (*.xls), *.xls", _
            Title:="My custom save dialog")
    
        If vFile <> False Then
            ThisWorkbook.SaveAs Filename:=vFile
        Else
            MsgBox "Not a valid path" 'cancel
        End If
        ' change back to initial current directory
        ChDrive sCurrDir
        ChDir sCurrDir
    
    End Sub
    But I am hoping to have the export run and for it to save to specific predefined place ("C:....") and name (Value from Cell A10) with a time stamp. Any thoughts?

    Thanks!

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,192

    Re: VBA: Saving a Exported XML with a predefined file name with a time stamp

    vPath = "c:\folder\
    vName = range("A10").value & "_" & format(now(),"yymmdd-hhnn") & ".xls"
    vFile= vPath & vName

    activeworkbook.saveas vFile


    (you dont need the chDir, chDrive commands)

  3. #3
    Registered User
    Join Date
    08-05-2015
    Location
    Hartford, CT
    MS-Off Ver
    MS Office 2010
    Posts
    2

    Re: VBA: Saving a Exported XML with a predefined file name with a time stamp

    So I was able to figure it out. Instead of using a command to hit the ribbon button I found the actual command for exporting the XML.

     Sub ExportXML()
        '
        ' ExportXML Macro
        '
        Dim objMapToExport As XmlMap
        
         Set objMapToExport = ActiveWorkbook.XmlMaps("DocumentRequests_Map")
        
         ActiveWorkbook.SaveAsXMLData [c12] & [c9] & Format(Now, "dd-mm-yy h-mm-ss") & ".xml", objMapToExport
            
        
        'This opens the folder so you can see the saved file
        Call Shell("explorer.exe" & " " & [c12], vbNormalFocus)
        
        '
        End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Save File with Date and Time Stamp
    By Andibevan in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-26-2019, 12:46 AM
  2. [SOLVED] Saving csv file with Date Stamp
    By drewan187 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2014, 08:56 AM
  3. Wrong Time stamp when a File is saved
    By bobbydsi in forum Excel General
    Replies: 6
    Last Post: 07-12-2011, 10:15 AM
  4. Saving in a second location with date/time stamp
    By lxndeb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-29-2009, 01:42 PM
  5. Time & date stamp when saving a shared worksheet
    By jamie.c in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-20-2009, 04:37 AM
  6. Save file with time date stamp
    By oberon.black in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2005, 09:05 PM
  7. [SOLVED] Getting a File Date & Time stamp
    By James in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-08-2005, 04:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1