Results 1 to 3 of 3
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open File From Desktop (97:SR2)

    I would like to open a file to the desktop. Is it possible?

    Example Code:
    Open "DesktopYourFile.Txt" For Append As #2
    Print #2, "Blah Blah Blah"
    Close #2

    Thanks,
    John

    PS - The XL file will be shared and I don't know who's desktop to send it to.

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

    Re: Open File From Desktop (97:SR2)

    If your question is how to locate the desktop of the user, here is code using Windows API calls to retrieve the user's desktop folder <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

    <img src=/w3timages/blueline.gif width=33% height=2>

    Public Const CSIDL_DESKTOP = &H0

    Private Type ######EMID
    cb As Long
    abID As Byte
    End Type

    Private Type ITEMIDLIST
    mkid As ######EMID
    End Type

    Private Declare Function SHGetSpecialFolderLocation _
    Lib "shell32.dll" _
    (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long

    Private Declare Function SHGetPathFromIDList _
    Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
    (ByVal pidl As Long, ByVal pszPath As String) As Long

    Public Function GetSpecialFolder(CSIDL As Long) As String
    Dim r As Long
    Dim IDL As ITEMIDLIST
    Dim Path As String
    'Get the special folder
    r = SHGetSpecialFolderLocation(100, CSIDL, IDL)
    If r = 0 Then
    'Create a buffer
    Path = Space$(512)
    'Get the path from the IDList
    r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$)
    'Remove the unnecessary chr$(0)'s
    GetSpecialFolder = Left$(Path, InStr(Path, Chr$(0)) - 1)
    Exit Function
    End If
    GetSpecialFolder = ""
    End Function

    <img src=/w3timages/blueline.gif width=33% height=2>

    To get the desktop, use GetSpecialFolder(CSIDL_DESKTOP). So you could use

    Open GetSpecialFolder(CSIDL_DESKTOP) & "YourFile.txt" For Append As #2

    If you meant something else, please specify.

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open File From Desktop (97:SR2)

    Hans,

    Exactly what I was after.

    Many thanks,
    John

Posting Permissions

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