Consulting

Results 1 to 14 of 14

Thread: Solved: Save Excel Workbook on users desktop

  1. #1

    Solved: Save Excel Workbook on users desktop

    Hi, this is my first post on your forum. Hopefully I am described my problem clearly, if you require further information please give me a shout.
    Cheers, Stig.

    I am using a VB macro on a survey designed on MS Excel. The survey is published on our work intranet and is set-up to return the completed survey to a central email account through the users Lotus Notes or Outlook account.

    The problem I am experiencing is that before the form is returned it must be saved, and I have no control over where the form is saving using the code below.

    Ideally I would like the survey to be saved on the users desktop, can you please advise how the code can be changed to allow this to happen: -

    [vba]
    ans = MsgBox("Do you want to make any more changes to the survey before sending?", vbYesNo)
    If ans = vbYes Then
    Exit Sub
    End If
    ThisWorkbook.SaveAs FileName:=Sheets("Details").Range("R2"), FileFormat:=xlNormal, _
    Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False
    ActiveWorkbook.RunAutoMacros (xlAutoClose)
    FullPath = ThisWorkbook.FullName
    FileName = ThisWorkbook.Name
    [/vba]

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Try this but change the path to suit:
    [VBA]ActiveWorkbook.SaveAs FileName:="F:\Temp\BOM.xls", FileFormat:=xlNormal, _
    Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False
    Application.Run "checkname"[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    For saving to the desktop specifically:
    [VBA]
    Sub SaveToDesktop()
    Dim DTAddress As String
    DTAddress = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
    ActiveWorkbook.SaveAs DTAddress & "Your File Name.xls"
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Hi Lucas,

    Thanks for you help on this one I am going to try using the second line of code you suggested that saves the document to the users desktop. Can you advise how I can incorporate the code below into the filename.

    Cheers

    [VBA]
    FileName:=Sheets("Details").Range("R2")
    [/VBA]

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is what Steve gave you

    [vba]

    Dim DTAddress As String
    DTAddress = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
    ActiveWorkbook.SaveAs Filename:=DTAddress & Sheets("Details").Range("R2").Value

    [/vba]

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    This seems to work on a quick try:
    [VBA]
    Sub SaveToDesktop()
    Dim DTAddress As String
    DTAddress = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
    ActiveWorkbook.SaveAs DTAddress & Sheets("Details").Range("R2")
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Bob,
    is the .value necessary?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    Thanks Steve & Bob,
    Your advice worked a treat and saved me a whole lot of time and effort.
    Thanks again

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi Stig,
    glad it works for you....be sure to mark your thread solved using the thread tools at the top of the page.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lucas
    Hi Bob,
    is the .value necessary?
    Don't get me started Steve!

    Only lazy, slobby programmers omit the default property .

  11. #11
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Quote Originally Posted by xld
    Don't get me started Steve!

    Only lazy, slobby programmers omit the defauly property .


    I've been explicitly using all default values since I found out that .NET requires you to use them (not to mention I, too, feel it's better programming practice).




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  12. #12
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Ok, thanks guys for the honest replies every little bit helps.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  13. #13
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Quote Originally Posted by xld
    Only lazy, slobby programmers omit the default property .
    Forget MVP, looks like I'll just have to settle for LSP
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  14. #14
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I knew there was an acronym for my skill level
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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