Consulting

Results 1 to 5 of 5

Thread: How to reach the desktop while avoiding "USERNAME"

  1. #1
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location

    How to reach the desktop while avoiding "USERNAME"

    Hi all,

    when I had some trouble with a few macros, copying picutres from a hidden presentation, I learnt that

    Environ$("USERNAME") & "\AppData\Roaming\Microsoft\AddIns\"
    does not work on every machine, as the USERNAME seems to be not defined correctly anywhere. Or whatever the reason is.


    Environ$("appdata") & "\Microsoft\AddIns\"
    worked more successful on these machines.


    But is there a way to reach the desktop, too?

    I have one macro, creating a folder on the desktop and storing some things there - and it should be on the desktop, as the user needs to find it later. Until now, I used

    Environ("USERPROFILE") & "\Desktop\Name_of_the_new_folder\"

    Is there a way to avoid using "USERPROFILE" here, too?


    Environ("desktop") & "\Name_of_the_new_folder\"
    is not working. But maybe there is something like this? Does anyone know?


    Thank you!
    RG

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    See if this is more reliable for you

    Option Explicit
    
    Sub WheresMyDesktop()
    
        Dim sDesktopPath As String
    
        sDesktopPath = CreateObject("Shell.Application").Namespace(CVar(0)).Self.Path
    
        MsgBox sDesktopPath
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    As well as Paul's method and USERPROFILE you can also say:

    Sub findDT()
    Dim oWSHShell As Object
    Dim sDesktopPath As String
        Set oWSHShell = CreateObject("WScript.Shell")
        sDesktopPath = oWSHShell.SpecialFolders("Desktop")
        MsgBox sDesktopPath
        Set oWSHShell = Nothing
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Thank you, Paul and John,

    in deed, both codes work great. Are there any arguments for prefering one of them? Maybe not compatible to PPT2007 or whatever ...

  5. #5
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    167
    Location
    Obviously there are not. :-)

    Once again, thank you!

Posting Permissions

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