+ Reply to Thread
Results 1 to 5 of 5

VBA Save to 2 locations including Users desktop

Hybrid View

michelle 1 VBA Save to 2 locations... 06-19-2024, 01:09 PM
mjr veverka Re: VBA Save to 2 locations... 06-19-2024, 11:09 PM
michelle 1 Re: VBA Save to 2 locations... 06-20-2024, 03:52 AM
protonLeah Re: VBA Save to 2 locations... 06-19-2024, 11:10 PM
jdelano Re: VBA Save to 2 locations... 06-20-2024, 04:01 AM
  1. #1
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    325

    VBA Save to 2 locations including Users desktop

    Dear ALL

    is it possible to add to the below code a step that will also save to the users desktop. I have replaced the current location with XX just for privacy purposes.

    Public Sub MASSUPLOAD()
        
        Dim newWb As Workbook
        Dim wbConn As WorkbookConnection
        Dim wbQuery As WorkbookQuery
        Dim links As Variant, i As Long
        
        ThisWorkbook.Worksheets(Array("Patient Fields", "Sheet1")).Copy
        Set newWb = ActiveWorkbook
        
        'Delete workbook connections
        
        For Each wbConn In newWb.Connections
            wbConn.Delete
        Next
        
        'Delete workbook queries
        
        For Each wbQuery In newWb.Queries
            wbQuery.Delete
        Next
        
        'Delete Excel links
        
        'links = newWb.LinkSources(xlExcelLinks)
        'If links <> Empty Then
         '   For i = 1 To UBound(links)
          '      newWb.BreakLink links(i), xlLinkTypeExcelLinks
           ' Next
        'End If
        
        Worksheets(Array("Patient Fields")).Select
        Range("A3").Select
        ActiveSheet.Shapes.Range(Array("Rectangle: Rounded Corners 2")).Select '
        Selection.Delete
        Selection.Cut
        
        Application.DisplayAlerts = False 'suppress warning message displayed if new workbook already exists
        newWb.SaveAs "XXXXX/" & "\" & "XXXX_" & Format$(Now(), "YYmmdd_hhmmss") & ".xlsx", FileFormat:=xlOpenXMLWorkbook
        Application.DisplayAlerts = True
        newWb.Close False
        
    End Sub

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,267

    Re: VBA Save to 2 locations including Users desktop

    ???
    Option Explicit
    
    Public Sub MASSUPLOAD_01()
        Dim elmnt As Variant, i As Long
        
        ThisWorkbook.Worksheets(Array("Patient Fields", "Sheet1")).Copy
            With ActiveWorkbook
                With .Worksheets("Patient Fields")
                    .Shapes.Range("Rectangle: Rounded Corners 2").Delete
                    .Range("A3").Delete
                End With
                For Each elmnt In .Queries
                    elmnt.Delete
                Next
                For Each elmnt In .Connections
                    elmnt.Delete
                Next
                'elmnt = .LinkSources(xlExcelLinks)
                'If elmnt <> Empty Then
                '   For i = LBound(elmnt) To UBound(elmnt)
                '      .BreakLink elmnt(i), xlLinkTypeExcelLinks
                '   Next
                'End If
                elmnt = CreateObject("Wscript.Shell").SpecialFolders("Desktop")
                .SaveAs elmnt & "\" & Format$(Now(), "YYmmdd_hhmmss") & ".xlsx", FileFormat:=51
                .Close False
            End With
        DoEvents
    End Sub

  3. #3
    Forum Contributor
    Join Date
    07-02-2013
    Location
    abbots langley
    MS-Off Ver
    Excel 2010
    Posts
    325

    Re: VBA Save to 2 locations including Users desktop

    Thankyou this does save to my desktop but i now have 2 buttons one that is saving to my desktop and one to the folder is there anyway to combine the code so its all done via one button?

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,960

    Re: VBA Save to 2 locations including Users desktop

    You need lines something like:
        ChDir "C:\Users\ben\Desktop"
        ActiveWorkbook.SaveAs Filename:= ...
    Ben Van Johnson

  5. #5
    Valued Forum Contributor
    Join Date
    09-18-2023
    Location
    Geogia, USA
    MS-Off Ver
    365
    Posts
    314

    Re: VBA Save to 2 locations including Users desktop

    Try using SaveCopyAs after your

    .SaveAs elmnt & "\" & Format$(Now(), "YYmmdd_hhmmss") & ".xlsx", FileFormat:=51
    Put
    .SaveCopyAs Environ("USERPROFILE") & "\Desktop\" & Format$(Now(), "YYmmdd_hhmmss") & ".xlsx"
    https://learn.microsoft.com/en-us/of...ook.SaveCopyAs

    EDIT: You'll want to just combine that one SaveAsCopy line to the button that saves the first file

+ 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 PDF to users desktop and use value of specific cell in part of the name
    By Maike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-20-2017, 04:33 PM
  2. Change my vba code to save excel file directly to any users desktop not via c drive
    By galbatrox9 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-22-2016, 01:22 AM
  3. Save as button to desktop working for all users
    By Niels57440 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-30-2016, 07:52 AM
  4. VBA to Save the Selected Area as a PDF to the Users DeskTop
    By Sean Gillan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2015, 05:10 PM
  5. [SOLVED] VBA: Create a new folder on any users desktop and save the file as value in cell (A51)
    By nwb in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-24-2014, 11:02 PM
  6. [SOLVED] Macro to save mail merged word docs to users desktop and with a desired file name
    By bonny24tycoon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2012, 12:27 PM
  7. [SOLVED] How would I save a text file to a folder on the users desktop without knowing the path?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-21-2012, 01:36 PM

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