|
-
Sep 26th, 2005, 12:00 PM
#1
[RESOLVED] Excel Autostart macro..?
Ok, I know you can add an xls file to the XLStart folder and it will always load that first, and you can add code to run... but here is my problem
I Need to run code on every workbook that is opened.. The Autostart xls file is no good because it runs the code BEFORE the next workbook opens.
How can I run code on the workbook that is being opened? (Without having to code every workbook because that is not possible for this situation)
(basically I need to set the print options in excel for header/footer so that ever workbook prints the same)
Thanks!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 26th, 2005, 12:19 PM
#2
Addicted Member
Re: Excel Autostart macro..?
use one of your workbooks as an example and record a new macro doing what you want - most of this vba code should copy over to vb - not the most elegant of solns but it works assuming that you want to do the same 'thing' to all of your workbooks
-
Sep 26th, 2005, 12:19 PM
#3
Re: Excel Autostart macro..?
Moved from Classic VB forum. 
Are they being opened manually?
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 
-
Sep 26th, 2005, 12:31 PM
#4
Re: Excel Autostart macro..?
yes... say the user get a file off e-mail.. or the lan... etc..
double clicks to open.. bam I want to re-format the printing.
how about an add-in? (Never made one but maybe?)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 26th, 2005, 12:42 PM
#5
Re: Excel Autostart macro..?
Yes, an addin would be perfect as long as the users are not running an older version of Excel that may not support your formatting functions you use.
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 
-
Sep 26th, 2005, 12:43 PM
#6
Re: Excel Autostart macro..?
with an Add-in.. would the user have to run it each time? or can it be triggered every time a new workbook is opened? (How do I do that!!)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 26th, 2005, 12:51 PM
#7
Re: Excel Autostart macro..?
To be honest I havent created many Excel addins (.xla) but VB Add-Ins have an OnConnection and OnStartupComplete. You could also create the Workbook_New or Workbook_Open events.
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 
-
Sep 26th, 2005, 01:33 PM
#8
Re: Excel Autostart macro..?
Excel add-ins seem to have NOTHING! ..hmmm
will play around a bit.. probably be back soon to ask another ?
Thanks
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 26th, 2005, 02:17 PM
#9
Re: Excel Autostart macro..?
nope..
I cant seem to get it to "hit" the other workbooks.
if I use it as an addin.. it will run the code on the addin first, then open the workbook you are opening.
any other ideas?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 26th, 2005, 02:22 PM
#10
Re: Excel Autostart macro..?
Other then creating a global hook for the creation of a new window and check if its an Excel window. I'm not sure what else you could do.
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 
-
Sep 26th, 2005, 03:26 PM
#11
Re: Excel Autostart macro..?
well.. its not pretty but might work:
xlt file that will format all NEW workbooks...
and a Personal.xls file that has an API timer...
every minute it looks at all workbooks open..
if the open workbook is not in its list of "previously formatted" books
then it formats it.. otherwise it skips it.
(I see holes in this one lol! but its a start)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 27th, 2005, 07:16 AM
#12
Lively Member
Re: Excel Autostart macro..?
Can I just ask why every workbook? Cannot see why the print options are not set before distribution but hey:
Try this code in your personal.xls:
Goes into a class module:
VB Code:
Public WithEvents App As Application
Private Sub App_NewWorkbook(ByVal Wb As Workbook)
' your code here
MsgBox "A new workbook is created!"
End Sub
Then this goes in the ThisWorkbook code module of the personal.xls:
VB Code:
Dim ApplicationClass As New AppEventClass
Private Sub Workbook_Open()
Set ApplicationClass.App = Application
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set ApplicationClass.App = Nothing
End Sub
-
Sep 27th, 2005, 07:45 AM
#13
Re: Excel Autostart macro..?
Justin! You are Awesome!
I was so close.. but yet couldnt quite get the events...
this line is my saviour: "Public WithEvents App As Application"
Excelent... thank you!! thank you!!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 27th, 2005, 07:59 AM
#14
Re: Excel Autostart macro..?
oh, Justin, every workbook is for audit.. so it always prints Filename / Author / Date&Time
Thanks Again
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 27th, 2005, 08:51 PM
#15
Lively Member
Re: [RESOLVED] Excel Autostart macro..?
Glad to help, you can also look into putting the code into an Add-in and just keeping the addin loaded when the AppEvents are needed. I use this method as I never have used a Personal.xls.
Hope it goes well......
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
|