[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.
Re: Open a file located on any windows xp desktop
search in this forum on getspecialfolder, there are many examples
1 Attachment(s)
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.
Re: Open a file located on any windows xp desktop
Re: Open a file located on any windows xp desktop
You've got 2 replies. What's the problem?
Re: Open a file located on any windows xp desktop
Could someone give an example
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!
:wave:
Re: Open a file located on any windows xp desktop
I don’t understand what is the problem if somebody write an example.
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.
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
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.
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?
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?
Re: Open a file located on any windows xp desktop
Thanks abhijit Both worked