Desktop in VB
Desktop in VB
I have been converting a VB for Excel to VB for Calc program I developed. Things are really starting to fall into place and I am trying to save my new spreadsheet into a folder on the desktop.
In VB the term "desk" pointed to the desktop under Calc I am having a problem. I am fairly confident the save process is working because I can save to "C:\STEVE\STEVE.ODS" and it works. If I do desk & "\STEVE\STEVE.ODS" I get a runtime error. STEVE is a valid folder on the desktop.
Thanks,
In VB the term "desk" pointed to the desktop under Calc I am having a problem. I am fairly confident the save process is working because I can save to "C:\STEVE\STEVE.ODS" and it works. If I do desk & "\STEVE\STEVE.ODS" I get a runtime error. STEVE is a valid folder on the desktop.
Thanks,
Open Office 3.1 and Visual Basic 2008
Re: Desktop in VB
In OOo basic I would have to use the full path name
C:\Documents and Settings\username\Desktop\Steve\Steve.ods.
If you try the analogous path on your system, does it work? I'm using Windows XP and I can get the path by right clicking on any file on the desktop and selecting Properties. On the General tab there is a Location listed that shows the whole directory path.
C:\Documents and Settings\username\Desktop\Steve\Steve.ods.
If you try the analogous path on your system, does it work? I'm using Windows XP and I can get the path by right clicking on any file on the desktop and selecting Properties. On the General tab there is a Location listed that shows the whole directory path.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Desktop in VB
desk in VB gives the path to the desktop on the machine running my app.
There are more than one user that my app is going to be using and their desktop is addressed with a different user. I was quite surprised desk did not work like it did in my vb program with Excel. I would think a directory would not matter which spreadsheet it is creating.
In you example you are hard coding the user I cannot do that in mine.
There are more than one user that my app is going to be using and their desktop is addressed with a different user. I was quite surprised desk did not work like it did in my vb program with Excel. I would think a directory would not matter which spreadsheet it is creating.
In you example you are hard coding the user I cannot do that in mine.
Open Office 3.1 and Visual Basic 2008
-
- Volunteer
- Posts: 1160
- Joined: Mon Oct 08, 2007 1:26 am
- Location: France, Paris area
Re: Desktop in VB
Hi,
______
Bernard
What is the resulting address ? OpenOffice cannot understand Windows nicknames, you have to provide a complete and correct address. Use environment variables to find it.thepla wrote:In VB the term "desk" pointed to the desktop under Calc I am having a problem. I am fairly confident the save process is working because I can save to "C:\STEVE\STEVE.ODS" and it works. If I do desk & "\STEVE\STEVE.ODS" I get a runtime error. STEVE is a valid folder on the desktop.
______
Bernard
Re: Desktop in VB
Figured out my own answer. In a previous program I developed, for Excel, I had line in code to get desktop. Here it is in case someone needs the line.
desk = CreateObject("WScript.Shell").Specialfolders(10)
desk = CreateObject("WScript.Shell").Specialfolders(10)
Open Office 3.1 and Visual Basic 2008
-
- Volunteer
- Posts: 1160
- Joined: Mon Oct 08, 2007 1:26 am
- Location: France, Paris area
Re: Desktop in VB
Better code :
Code: Select all
desk = CreateObject("WScript.Shell").SpecialFolders("Desktop")
Bernard
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
Re: Desktop in VB
I agree, changed my program and it works. Much easier to read in the future.B Marcelly wrote:Better code :Code: Select all
desk = CreateObject("WScript.Shell").SpecialFolders("Desktop")
Thanks
Open Office 3.1 and Visual Basic 2008
Re: Desktop in VB
I might mention that CreateObject("Wscript.Shell") shows some inconsistencies from time to time. See the discussion in this thread http://user.services.openoffice.org/en/ ... 41#p110342
Edit: Ooops, sometimes I am blinded by the bare wish to spread my knowledge. I looked at the title again, and I realised, that you are working inside MS Visual Basic. Of course CreateObject("Wscript.Shell") works inside VB without any flaws. On second thought this means that this thread talks about how to figure out the MS Windows User's Desktop path with MS Visual Basic. This has nothing to do with OOo BASIC and nothing with any of the OpenOffice applications. So you should have better chosen a different forum for your question. |
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
-
- Volunteer
- Posts: 1160
- Joined: Mon Oct 08, 2007 1:26 am
- Location: France, Paris area
Re: Desktop in VB
I will answer here because the other thread is a mess.rudolfo wrote:I might mention that CreateObject("Wscript.Shell") shows some inconsistencies from time to time. See the discussion in this thread http://user.services.openoffice.org/en/ ... 41#p110342
Collections, like SpecialFolders, have a property Item from which you get the item corresponding to an index.
In VB, VBScript or JScript this is a default property, it can be omitted.
In OOoBasic you cannot omit the property Item.
Code: Select all
Option Explicit
Sub Main ' --- This is OpenOffice.org Basic ---
Dim wsh As Variant
Dim folderName As String
wsh = CreateObject("WScript.Shell")
folderName = "Desktop"
MsgBox(wsh.SpecialFolders.Item(folderName), 0, folderName)
End Sub
Bernard
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
Re: Desktop in VB
Thanks Bernard,
this spreads a lot of light on the behaviour of CreateObject. As it is often emphasized that OOo does not fully support VBA (or rather that the support is very limited) I assumed that the support for OLE/COM/ActiveX objects on Windows systems isn't complete, either.
My assumption is wrong. And your answer makes perfectly sense because the COM interface doesn't depend on the programming language that is used to work with it. The crucial point is that there are a lot of pitfalls if your thinking is VB biased. I will keep this in mind for the future.
this spreads a lot of light on the behaviour of CreateObject. As it is often emphasized that OOo does not fully support VBA (or rather that the support is very limited) I assumed that the support for OLE/COM/ActiveX objects on Windows systems isn't complete, either.
My assumption is wrong. And your answer makes perfectly sense because the COM interface doesn't depend on the programming language that is used to work with it. The crucial point is that there are a lot of pitfalls if your thinking is VB biased. I will keep this in mind for the future.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.