[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
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
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
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
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?
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