Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetObject problem

Status
Not open for further replies.

rookery

Programmer
Apr 4, 2002
384
GB
I've searched the KB and past posts in here without success so far. Basically I'm using the following code to display an Excel file, the name of which I have in a ListBox. This is under the double_click event:

Dim Obj as Object

Set Obj = GetObject(Me.ListAssDocs) ' full path here
Obj.Application.Visible = True
Exit Sub

Although Excel opens I cant get it to display the specific file. How do I get it to do this? I cant declare Obj as an Excel Application as there will be occasions when the user will want to open a PowerPoint file etc.
 
Hi,

not sure if this helps, but you could use the value in your list box as a temporary hyperlink address, which would solve the problem of different filetypes... I used this bit of code on a combobox, I'm sure you could do the same on a list box...

Private Sub cmbFilePath_DblClick(Cancel As Integer)
With Me.hypTemp
.HyperlinkAddress = Me.cmbFilePath.Value
.Hyperlink.Follow
End With ' me.hypTemp
End Sub
 
The hyperlink way is easiest. You can add
Obj.Windows(1).Visible = True
to make your Excel file visible, but this doesn't work with Word files
 
Thanks for your responses. I managed to get the Excel document to work by using the following code:

Obj.Application.Windows(strFileName).Visible = True

As this code doesn't work with Word I've had to set up a Select Case procedure which checks the extension of the file I'm trying to open first of all (using the FileSystemObject method) and then opens the correct app depending on that.

Do you think this is the most efficient way of doing this? I was hoping that I'd be able to use just one procedure and feed in different parameters depending on what I was opening. eg. PowerPoint, Excel, Word file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top