|
-
Jun 7th, 2005, 04:41 PM
#1
Thread Starter
New Member
Excel: workbooks.open doesn't work (not a newbie problem)
This one is small enough to try out on your own machine.
Book1 has this event procedure in the ThisWorkbook object:
VB Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Workbooks.Open "SomeWorkbook"
MsgBox "foo"
End Sub
Book2 has this sub in a code module:
VB Code:
Sub test()
Dim wb As Workbook
Set wb = Workbooks.Open("Book1.xls")
wb.PrintOut
End Sub
When I run test() in Book2, Book1 opens, msgboxes the 'foo' and prints, but the Workbooks.Open "SomeWorkbook" line doesn't do anything. Is there any way to make it work? Maybe the Workbooks.Open calls can't be nested, but I can't find any indication of this in documentation. Thanks for you help.
Will
Last edited by tranner; Jun 9th, 2005 at 01:17 PM.
-
Jun 7th, 2005, 04:49 PM
#2
Re: Excel: workbooks.open doesn't work (not a newbie problem)
Welcome to the Forums.
So your saying that the Workbooks.Open "SomeWorkbook" is not executing when opened and printed from book2.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 7th, 2005, 05:25 PM
#3
Thread Starter
New Member
Re: Excel: workbooks.open doesn't work (not a newbie problem)
Precisely. Now, if I open Book1 maually and print, the Workbooks.Open "SomeWorkbook" does work, and will throw an error is SomeWorkbook doesn't exist.
-
Jun 7th, 2005, 06:12 PM
#4
Re: Excel: workbooks.open doesn't work (not a newbie problem)
As a test, make sure ALL instances of Excel are closed and no instances are running in the taskmanager running processes list. Execute
your code and you should have showing 3 instances of Excel.exe.
It may be that its being shown as invisible if the last time it was saved it was hidden or invisible.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 7th, 2005, 07:01 PM
#5
Re: Excel: workbooks.open doesn't work (not a newbie problem)
as far as i can understand you have to do mare than just write a sub called beforeprint
Application events occur when a workbook is created or opened or when any sheet in any open workbook changes. To write event procedures for the Application object, you must create a new object using the WithEvents keyword in a class module. For more information, see Using Events with the Application Object.
Before you can use events with the Application object, you must create a new class module and declare an object of type Application with events. For example, assume that a new class module is created and called EventClassModule. The new class module contains the following code.
Public WithEvents App As ApplicationAfter the new object has been declared with events, it appears in the Object drop-down list box in the class module, and you can write event procedures for the new object. (When you select the new object in the Object box, the valid events for that object are listed in the Procedure drop-down list box.)
Before the procedures will run, however, you must connect the declared object in the class module with the Application object. You can do this with the following code from any module.
Dim X As New EventClassModule
Sub InitializeApp()
Set X.App = Application
End SubAfter you run the InitializeApp procedure, the App object in the class module points to the Microsoft Excel Application object, and the event procedures in the class module will run when the events occur.
information above from vba helpfile
pete
-
Jun 7th, 2005, 08:07 PM
#6
Re: Excel: workbooks.open doesn't work (not a newbie problem)
He is using the default events behind each workbook so no WithEvents are required. Also, the _BeforePrint event is
executing, just not the Workbooks.Open(Blah).
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 7th, 2005, 08:33 PM
#7
Re: Excel: workbooks.open doesn't work (not a newbie problem)
Looks like there is a limitation of one workbook opening another from another via automation.
I was searching earlier on MS and I couldnt find anything that states this. I would suggest that instead of daisy-chaining the opening of
workbooks, you have a central workbook to open all the wbs you need.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 9th, 2005, 01:17 PM
#8
Thread Starter
New Member
Re: Excel: workbooks.open doesn't work (not a newbie problem)
I guess it's to prevent a recursive loop of opening workbooks. Weird how this isn't documented though. Oh well.
-
Jun 9th, 2005, 01:41 PM
#9
Re: Excel: workbooks.open doesn't work (not a newbie problem)
Thats what I was thinking and also that it may come from a security standpoint. Dont want to open a workbook and have it
open "other" malicious workbooks, etc. like some virus' and spam.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|