ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using workbooks.open after new instance of excel application (https://www.excelbanter.com/excel-programming/310091-using-workbooks-open-after-new-instance-excel-application.html)

George J

Using workbooks.open after new instance of excel application
 
Basically, i have a workbook that when opened, displays a
userform with three buttons. (I only need the first one.)
When this button is pressed it will open up another excel
application and workbook.

'--------------------------------------------
Private Sub CommandButton1_Click()
Dim xlApp As Object
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True

If Not xlApp Is Nothing Then
xlApp.Workbooks.Open FileName:="C:\test2 - del.xls"
End If

End Sub
'--------------------------------------------

This part works ok in opening Test2 - del.xls in a new
instance of excel.

In this new workbook i cannot open another workbook.

'--------------------------------------------
Private Sub Workbook_Open()
Dim wb As Workbook

Workbooks.Open FileName:="C:\George J.xls"
End Sub
'--------------------------------------------

My original code is more complicated than this but if
anyone can tell me how to get this working i will be
extremely grateful. I am using excel97

thanks
George

Tom Ogilvy

Using workbooks.open after new instance of excel application
 
Why not

Private Sub CommandButton1_Click()
Dim xlApp As Object
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True

If Not xlApp Is Nothing Then
xlApp.Workbooks.Open FileName:="C:\test2 - del.xls"
xlApp.Workbooks.Open FileName:="C:\George J.xls"
End If

End Sub

--
Regards,
Tom Ogilvy


"George J" wrote in message
...
Basically, i have a workbook that when opened, displays a
userform with three buttons. (I only need the first one.)
When this button is pressed it will open up another excel
application and workbook.

'--------------------------------------------
Private Sub CommandButton1_Click()
Dim xlApp As Object
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True

If Not xlApp Is Nothing Then
xlApp.Workbooks.Open FileName:="C:\test2 - del.xls"
End If

End Sub
'--------------------------------------------

This part works ok in opening Test2 - del.xls in a new
instance of excel.

In this new workbook i cannot open another workbook.

'--------------------------------------------
Private Sub Workbook_Open()
Dim wb As Workbook

Workbooks.Open FileName:="C:\George J.xls"
End Sub
'--------------------------------------------

My original code is more complicated than this but if
anyone can tell me how to get this working i will be
extremely grateful. I am using excel97

thanks
George




George J

Using workbooks.open after new instance of excel application
 
Oh, if only i could.

As i said, this is a dumbed down example of what i am
trying to do.

When the workbook "Test2 - del" is opened it will show a
userform for data input. This will create new workbooks
and open existing workbooks based on various combobox
values.

Due to the calculations involved, i wanted only 2
workbooks opened in the application. This would be
the "Test2 - del" (which has the userform i didn't mention
before), and whatever has been selected or created by the
settings of the comboboxes - in my example it was "George
J"

When the button on the userform in "test2 - del" is
pressed, it is not known at this point what other workbook
needs to be opened.

sorry if this is getting confusing.
George

-----Original Message-----
Why not

Private Sub CommandButton1_Click()
Dim xlApp As Object
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True

If Not xlApp Is Nothing Then
xlApp.Workbooks.Open FileName:="C:\test2 - del.xls"
xlApp.Workbooks.Open FileName:="C:\George J.xls"
End If

End Sub

--
Regards,
Tom Ogilvy


"George J" wrote in

message
...
Basically, i have a workbook that when opened, displays

a
userform with three buttons. (I only need the first

one.)
When this button is pressed it will open up another

excel
application and workbook.

'--------------------------------------------
Private Sub CommandButton1_Click()
Dim xlApp As Object
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True

If Not xlApp Is Nothing Then
xlApp.Workbooks.Open FileName:="C:\test2 - del.xls"
End If

End Sub
'--------------------------------------------

This part works ok in opening Test2 - del.xls in a new
instance of excel.

In this new workbook i cannot open another workbook.

'--------------------------------------------
Private Sub Workbook_Open()
Dim wb As Workbook

Workbooks.Open FileName:="C:\George J.xls"
End Sub
'--------------------------------------------

My original code is more complicated than this but if
anyone can tell me how to get this working i will be
extremely grateful. I am using excel97

thanks
George



.


George J

Using workbooks.open after new instance of excel application
 
Worked it out.

Well, not why it wasn't working, but how to get it to work.
All i needed was:

Private Sub CommandButton1_Click()
shell "excel.exe" & chr(34) & "C:\test2 - del.xls" & chr
(34)
end sub

Had never use shell commands before and know there were
problems if you used long filenames or had spaces. Puting
double quotation marks around it sorted those problems,
but never thought of how to get this past the debugger in
VBE.

I'm happy!!

thanks for the reply Tom.
George
-----Original Message-----
Oh, if only i could.

As i said, this is a dumbed down example of what i am
trying to do.

When the workbook "Test2 - del" is opened it will show a
userform for data input. This will create new workbooks
and open existing workbooks based on various combobox
values.

Due to the calculations involved, i wanted only 2
workbooks opened in the application. This would be
the "Test2 - del" (which has the userform i didn't

mention
before), and whatever has been selected or created by the
settings of the comboboxes - in my example it was "George
J"

When the button on the userform in "test2 - del" is
pressed, it is not known at this point what other

workbook
needs to be opened.

sorry if this is getting confusing.
George

-----Original Message-----
Why not

Private Sub CommandButton1_Click()
Dim xlApp As Object
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True

If Not xlApp Is Nothing Then
xlApp.Workbooks.Open FileName:="C:\test2 - del.xls"
xlApp.Workbooks.Open FileName:="C:\George J.xls"
End If

End Sub

--
Regards,
Tom Ogilvy


"George J" wrote

in
message
...
Basically, i have a workbook that when opened,

displays
a
userform with three buttons. (I only need the first

one.)
When this button is pressed it will open up another

excel
application and workbook.

'--------------------------------------------
Private Sub CommandButton1_Click()
Dim xlApp As Object
Set xlApp = CreateObject("excel.application")
xlApp.Visible = True

If Not xlApp Is Nothing Then
xlApp.Workbooks.Open FileName:="C:\test2 - del.xls"
End If

End Sub
'--------------------------------------------

This part works ok in opening Test2 - del.xls in a new
instance of excel.

In this new workbook i cannot open another workbook.

'--------------------------------------------
Private Sub Workbook_Open()
Dim wb As Workbook

Workbooks.Open FileName:="C:\George J.xls"
End Sub
'--------------------------------------------

My original code is more complicated than this but if
anyone can tell me how to get this working i will be
extremely grateful. I am using excel97

thanks
George



.

.



All times are GMT +1. The time now is 12:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com