Results 1 to 8 of 8
  1. #1
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Username in SaveAs FileName (VBA/Powerpoint/2000)

    Hi everyone.

    I've been having a hunt through the site to find out about the Username and came across this from Hans

    Private Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    Copy/paste the following function somewhere below it:

    Public Function WindowsUser() As String
    Dim strUsername As String
    strUsername = String(100, vbNullChar)
    GetUserName strUsername, 100
    WindowsUser = Left$(strUsername, InStr(strUsername, vbNullChar) - 1)
    End Function

    You can use this function to retrieve the Windows username, for example:

    Sub Test()
    MsgBox "Hello there, " & WindowsUser
    End Sub


    How do I include the username into ActivePresentation.SaveAs FileName:="Cocuments and SettingsMYUSERNAMEetc etc etc?

    many thanks

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Username in SaveAs FileName (VBA/Powerpoint/2000)

    If you want to get the My Documents folder of the current user, you can use
    <code>
    CreateObject("WScript.Shell").SpecialFolders("MyDo cuments")
    </code>
    For example:
    <code>
    ActivePresentation.SaveAs FileName:=CreateObject("WScript.Shell").SpecialFol ders("MyDocuments") & "BrilliantPresentation.ppt"</code>

  4. #3
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Username in SaveAs FileName (VBA/Powerpoint/2000)

    Thanks Hans, but is it not possible to put "& WindowsUser" into the file path where the username would usually be?

  5. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Username in SaveAs FileName (VBA/Powerpoint/2000)

    You can, but I don't understand why you would want that. Users can move their "My Documents" folder to another location. If they do,

    Cocuments and Settings<username>My Documents

    will not be valid any more. Similar if the user has a non-English version of Windows: My Documents will have a different name. The method from my previous reply will still return the correct path.

    But if you wish, you can use

    ActivePresentation.SaveAs FileName:="Cocuments and Settings" & WindowsUser & "..."

  6. #5
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Username in SaveAs FileName (VBA/Powerpoint/2000)

    Excellent. thanks Hans.

    This works. We have a strictly locked down enviornment here, so people are unable to change or move alot of the folders in "document and Settings"

    many thanks

    Thom

  7. #6
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Username in SaveAs FileName (VBA/Powerpoint/2000)

    Sorry about this Hans!

    I've just been trying

    ActivePresentation.SaveAs FileName:="Cocuments and Settings" & WindowsUser & "Application DataMicrosoftAddInsMyPres.ppa", FileFormat:=ppSaveAsAddIn, EmbedTrueTypeFonts:=msoFalse

    (including the code from the first post) but to no avail. it keeps saying "Path not found". I'm sure it's something very simple i'm missing!!

  8. #7
    Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Username in SaveAs FileName (VBA/Powerpoint/2000)

    Not to worry. Got it working.

    Thanks again

  9. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Username in SaveAs FileName (VBA/Powerpoint/2000)

    Probably the backslash after Documents and Settings that I forgot? <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

Posting Permissions

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