Results 1 to 14 of 14

Thread: [RESOLVED]Open a file located on any windows xp desktop

  1. #1

    Thread Starter
    Banned
    Join Date
    May 2003
    Posts
    37

    Resolved [RESOLVED]Open a file located on any windows xp desktop

    How can I write a program in VB6 to open a file located on any windows xp desktop.
    Any windows desktop means that the user name and the partition on which windows are installed are unknown.
    ?(partition C or D or E or .. ):\Documents and Settings\?(user name)\desktop\ test.txt
    Test.txt is the text file that we want to open.
    Last edited by jamesg; Nov 23rd, 2008 at 11:29 AM. Reason: Resolved

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Open a file located on any windows xp desktop

    search in this forum on getspecialfolder, there are many examples
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Open a file located on any windows xp desktop

    To get a list of all the drives on the system, you can use GetLogicalDriveStrings. I am attaching an example.
    Attached Files Attached Files

  4. #4

    Thread Starter
    Banned
    Join Date
    May 2003
    Posts
    37

    Re: Open a file located on any windows xp desktop

    Nobody?

  5. #5
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Open a file located on any windows xp desktop

    You've got 2 replies. What's the problem?

  6. #6

    Thread Starter
    Banned
    Join Date
    May 2003
    Posts
    37

    Re: Open a file located on any windows xp desktop

    Could someone give an example

  7. #7
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Open a file located on any windows xp desktop

    Quote Originally Posted by jamesg
    How can I write a program in VB6 to open a file located on any windows xp desktop.
    Any windows desktop means that the user name and the partition on which windows are installed are unknown.
    ?(partition C or D or E or .. ):\Documents and Settings\?(user name)\desktop\ test.txt
    Test.txt is the text file that we want to open.
    Read danecook's post!
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  8. #8

    Thread Starter
    Banned
    Join Date
    May 2003
    Posts
    37

    Re: Open a file located on any windows xp desktop

    I don’t understand what is the problem if somebody write an example.

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Open a file located on any windows xp desktop

    danecook posted one a week ago - none of us can understand why you are still asking for one.

  10. #10

    Thread Starter
    Banned
    Join Date
    May 2003
    Posts
    37

    Re: Open a file located on any windows xp desktop

    What I ask for is how can I write a program in VB6 to open a file located on any windows xp desktop and not to get the list of all the drives on the system

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Open a file located on any windows xp desktop

    I see, I hadn't spotted that... well in that case, following westconn1's advice is a good idea.

    This is the second result from that search (the first result being this thread), and it contains what you need.

  12. #12

    Thread Starter
    Banned
    Join Date
    May 2003
    Posts
    37

    Re: Open a file located on any windows xp desktop

    Sub GetDesktopFolder()
    Dim s As String
    s = CreateObject("WScript.Shell").Specialfolders("Desktop")
    End Sub

    Using above code s returns with C:\Documents and Settings\Current User \Desktop, which is the actual desktop path.

    I want to open an excel file the test.xls that is located in the Test Folder on the desktop.
    Using the following code VB returns with Error 1004 “s & \TestFolder\Test.xls could not be found. Check the spelling of the name and verify that the file location is correct”

    Sub GetDesktopFolder()
    Dim s As String
    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Dim xlSH As Excel.Worksheet
    s = CreateObject("WScript.Shell").Specialfolders("Desktop")
    Set xlApp = New Excel.Application
    Set xlWB = xlApp.Workbooks.Open(FileName:="s & \TestFolder\Test.xls")
    Set xlSH = xlWB.Worksheets(1)
    xlApp.Visible = True
    End Sub

    And with the following code VB returns with syntax Error and highlights in blue the
    Set xlWB = xlApp.Workbooks.Open(FileName:=" CreateObject("WScript.Shell").Specialfolders("Desktop") & \TestFolder\Test.xls")

    Sub GetDesktopFolder()
    Dim s As String
    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Dim xlSH As Excel.Worksheet
    s = CreateObject("WScript.Shell").Specialfolders("Desktop")
    Set xlApp = New Excel.Application
    Set xlWB = xlApp.Workbooks.Open(FileName:=" CreateObject("WScript.Shell").Specialfolders("Desktop") & \TestFolder\Test.xls")
    Set xlSH = xlWB.Worksheets(1)
    xlApp.Visible = True
    End Sub

    How to incorporate CreateObject("WScript.Shell").Specialfolders("Desktop") in the path in order to open the file?

  13. #13
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: Open a file located on any windows xp desktop

    Quote Originally Posted by jamesg
    Sub GetDesktopFolder()
    Dim s As String
    s = CreateObject("WScript.Shell").Specialfolders("Desktop")
    End Sub

    Using above code s returns with C:\Documents and Settings\Current User \Desktop, which is the actual desktop path.

    I want to open an excel file the test.xls that is located in the Test Folder on the desktop.
    Using the following code VB returns with Error 1004 s & “ \TestFolder\Test.xls could not be found. Check the spelling of the name and verify that the file location is correct”

    Sub GetDesktopFolder()
    Dim s As String
    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Dim xlSH As Excel.Worksheet
    s = CreateObject("WScript.Shell").Specialfolders("Desktop")
    Set xlApp = New Excel.Application
    Set xlWB = xlApp.Workbooks.Open(FileName:=s &" \TestFolder\Test.xls")
    Set xlSH = xlWB.Worksheets(1)
    xlApp.Visible = True
    End Sub

    And with the following code VB returns with syntax Error and highlights in blue the
    Set xlWB = xlApp.Workbooks.Open(FileName:=CreateObject("WScript.Shell").Specialfolders("Desktop") & "\TestFolder\Test.xls")

    Sub GetDesktopFolder()
    Dim s As String
    Dim xlApp As Excel.Application
    Dim xlWB As Excel.Workbook
    Dim xlSH As Excel.Worksheet
    s = CreateObject("WScript.Shell").Specialfolders("Desktop")
    Set xlApp = New Excel.Application
    Set xlWB = xlApp.Workbooks.Open(FileName:= CreateObject("WScript.Shell").Specialfolders("Desktop") & "\TestFolder\Test.xls")
    Set xlSH = xlWB.Worksheets(1)
    xlApp.Visible = True
    End Sub

    How to incorporate CreateObject("WScript.Shell").Specialfolders("Desktop") in the path in order to open the file?
    Could you please try with the changes in code?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  14. #14

    Thread Starter
    Banned
    Join Date
    May 2003
    Posts
    37

    Re: Open a file located on any windows xp desktop

    Thanks abhijit Both worked

Posting Permissions

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



Click Here to Expand Forum to Full Width