Solved

Shell Command

Posted on 1998-08-30
8
179 Views
Last Modified: 2010-04-30
Private Sub Form_Activate()
Dim openexcel
         
        openexcel = Shell("c:\Program Files\Microsoft Office\Office\excel c:\my documents\the worksheet.XLS", 1)
        AppActivate
       
End Sub


This command will not work because long filenames and spaces between the folder "my documents" and "The worksheet.xls"  I know that if I type in the dos name "Mydocu~1" it will work, but I need to have this set to a variable, instead of hard code.  Is there a function that will convert these so the computer will know how to open?

Thanks
0
Comment
Question by:thien
8 Comments
 
LVL 12

Expert Comment

by:mark2150
Comment Utility
Try phrasing it as:
quote = chr(34)
path = "c:\" & quote & "Program Files\Microsoft Office\Office\excel" & quote
file = "c:\" & quote & "my documents\the worksheet.XLS" & quote
openexcel = Shell(path & " " & file, 1)

In this way the quotes will be passed out to the SHELL command.

0
 

Author Comment

by:thien
Comment Utility
This does not work.  Tells me file is not found.  

David
0
 
LVL 1

Expert Comment

by:disha
Comment Utility
Hi David,
I dont think there is a problem with the command u have given because it works fine. Could u specify the exact error that it gives at u'r place.
Check out that excel works fine and also that the xls is present. I tried with other exe's ..it is working fine. check what ver of excel u r using and if it cannot accept filename as spaced in between.
Regards

0
 

Author Comment

by:thien
Comment Utility
Hi,

Again it does not work,error 53, File not found.  If I use the command the regular way,

openexcel = Shell("c:\Program Files\Microsoft Office\Office\excel c:\worksheet.XLS", 1)

The example above works, but if I change the path to C:\my documents, or to a worksheet that has a space in the name, then I get errors.  Your example does not work. Even though I know the file exists, it tells me it does not.

Thanks
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 3

Accepted Solution

by:
a111a111a111 earned 50 total points
Comment Utility
Here is a working code to get a short file name from a long file name.

The program and code are working fine.

If you need the exe I can email to you.


============  start here =============
' ***  in module1 ***
Option Explicit

Declare Function GetShortPathName Lib "kernel32" _
      Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
      ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

   Public Function GetShortName(ByVal sLongFileName As String) As String
       Dim lRetVal As Long, sShortPathName As String, iLen As Integer
       'Set up buffer area for API function call return
       sShortPathName = Space(255)
       iLen = Len(sShortPathName)

       'Call the function
       lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
       'Strip away unwanted characters.
       GetShortName = Left(sShortPathName, lRetVal)
   End Function

'===============================


' THe code in form1 ********

Option Explicit

Private Sub Command1_Click()
Dim msg As String
     CommonDialog1.filename = "*.*"
     CommonDialog1.ShowOpen
     
     msg = "Long File Name: " & CommonDialog1.filename & vbCrLf
     msg = msg & "Short File Name: " & GetShortName(CommonDialog1.filename)
     msg = msg & vbCrLf & "________________________________________________________"
     msg = msg & vbCrLf & vbCrLf & "http://www.hili.com/~shay   E-Mail: shayplace@hotmail.com"
     
     MsgBox msg
End Sub

Private Sub Command2_Click()
Unload Me
End Sub

Private Sub Form_Load()

End Sub




0
 
LVL 3

Expert Comment

by:a111a111a111
Comment Utility
Also you can download the exe from
http://www.hili.com/~shay/filename.zip
0
 
LVL 3

Expert Comment

by:a111a111a111
Comment Utility
You can modify the code as you wish.

0
 

Author Comment

by:thien
Comment Utility
Thank you This is Exactly What I need!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now