RUN TIME ERROR '91': 
Author Message
 RUN TIME ERROR '91':

I have finally figured out how to open an Excel file by dblclicking the
name in a FileListBox.  Below is the code I have written:

Private Sub ExcelList_DblClick()
'**********************************************
'Declaring Variables
'**********************************************
Dim Exc As Object
Dim File1 As String
Dim Path As String
Dim PathAndName As String
'**********************************************
'Stringing Variables together
'**********************************************
Path = ExcelList.Path
File1 = ExcelList.filename
PathAndName = Path + "\" + File1
'**********************************************
'Starting Excel and opening selcted file
'**********************************************
Exc = Shell("c:\msoffice\excel\excel.exe" + PathAndName, 1)

End Sub

I have a couple of problems however.  First and for most is the:
        Run-Time Error '91':
        Object Variable or With Block variable not set.

(Rectangle around the "Exc = Shell....." Line)  Excuse me for being a
newbie (I don't know the correct VB term for the Rectangle thang).

Can anyone see what is causing the error?  The above code does open the
selected file. Is there a place on the net where I can find a list of
definitions for the Error No.s'?

My second problem deals with the fact that if by chance the file listed
in the list box has a space in the name (LongFileNames - Win 95 blah
blah) the code takes the file name as seperate delimited names.

        example:
                If the file name in the file list box is:
                        Bid Pack #4 Budget.xls
                the program tries to open -
                        Bid.xls
                        Pack.xls
                        #4.xls
                        Budget.xls

I can't figure this out though because if I insert a - Msgbox File1 -
line in the code I get the correct File name in the message box.

If anyout could help out a new VBer I would appreciate it.

Thanks in advance,

Mike Key



Sat, 04 Sep 1999 03:00:00 GMT  
 RUN TIME ERROR '91':


23:20:18 -0600):

Quote:
>Exc = Shell("c:\msoffice\excel\excel.exe" + PathAndName, 1)

Insert a space after "excel.exe".

Quote:
> Is there a place on the net where I can find a list of
>definitions for the Error No.s'?

Produce your own list:

For i = 1 to 100 ' (or whatever you want)
 ' Print all Errors that are not "User definded error"s
 If Left$(Error$(i),4) <> "User" then debug.Print "Error #"
& Str$(i) & " is error: " & Error$(i)
Next i

Quote:
>My second problem deals with the fact that if by chance the file listed
>in the list box has a space in the name (LongFileNames - Win 95 blah
>blah) the code takes the file name as seperate delimited names.

>    example:
>            If the file name in the file list box is:
>                    Bid Pack #4 Budget.xls
>            the program tries to open -
>                    Bid.xls
>                    Pack.xls
>                    #4.xls
>                    Budget.xls

>I can't figure this out though because if I insert a - Msgbox File1 -
>line in the code I get the correct File name in the message box.

Right, if you tell Excel to load more than one file you
delimit them by spaces. It's logical. You might try to
either get the short filename or only shell the filename
(without the preceeding "Excel"). This will not work for VB3
BTW. For VB3 you might try the "ShellExecute"-API-call.

Mathias Schiffer, Germany



Sun, 05 Sep 1999 03:00:00 GMT  
 RUN TIME ERROR '91':

Quote:

> 'Stringing Variables together
> '**********************************************
> Path = ExcelList.Path
> File1 = ExcelList.filename
> PathAndName = Path + "\" + File1
> '**********************************************
> 'Starting Excel and opening selcted file
> '**********************************************
> Exc = Shell("c:\msoffice\excel\excel.exe" + PathAndName, 1)

> End Sub
> My second problem deals with the fact that if by chance the file listed
> in the list box has a space in the name (LongFileNames - Win 95 blah
> blah) the code takes the file name as seperate delimited names.

> Mike Key

Mike

        I see 2 potential items here:  I did not see a space between the
Excel.exe and the file name, and the file name itself should be
surrounded with double-quotes to avoid the long-file-name problem with
embedded spaces.  i.e. your command to send to shell should read

c:\msoffice\office.exe "Your file name here.xls"

and in VB Code this would look like

 Path = ExcelList.Path
 File1 = ExcelList.filename
 PathAndName = """" & Path + "\" + File1 & """"       ' surround with quotes
 Exc = Shell("c:\msoffice\excel\excel.exe" & " " &  PathAndName, 1)

Give this a try.  Good luck,

--
Jim Gilbert                   Monsanto Corp.

Legal Warning:
"By US Code Title 47, Sec.227(a)(2)(B), a computer / modem / printer
meets
the definition of a telephone fax machine.  By Sec. 227 (b)(1)(C), it is
unlawful to send any unsolicited adverti{*filter*}t to such equipment.  By
Sec.227(b)(3)(C), a violation of the aforementioned Section is
punishable
by action to recover actual monetary loss, or $500, whichever is
greater,
for each violation."



Sun, 05 Sep 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Run-time error '91' - HELP

2. run-time error '91'

3. Run Time Error '91'?

4. VB Run-time error '91'

5. Run-time error '91'

6. >Run-Time Error Message '91'

7. Run-time error '91' with ADODC Recordset commands

8. Run - time error '91' Object variable or With block variable not set

9. Run-time error '91' Object variable or With block variable not set

10. HELP : Error 91 : Run-Time Error 91 Object Variable or With

11. Error 91 running UpdateClass VBA macro from Sue Mosher's book

12. error '91'

 

 
Powered by phpBB® Forum Software