|
-
Dec 24th, 2004, 10:20 AM
#1
Thread Starter
Fanatic Member
Excel and cross-workbook code
I have an excel project that has modules and class modules which need to be in almost every workbook. It's a hassle to have to make sure every workbook has the most up to date code, and I was just wondering if there was some way to make code available to the entire excel application? DLLs maybe? (which I would go about making, how?)
Don't pay attention to this signature, it's contradictory.
-
Dec 24th, 2004, 12:37 PM
#2
Re: Excel and cross-workbook code
I see three ways to do it.
- Create an Excel Add-In.
- Create a dll.
- Use code to modify the macros in all workbooks
I havent done it myself for VBA but I would assume that if you create a VB Dll to do it
it would be the same. otherwise you would need the Developer version of
Office which can compile.
I think it may be easiest to use my CodeBank code to modify VBA code from VB (#3)!
You can check it out here.
HTH
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 
-
Dec 24th, 2004, 03:05 PM
#3
Thread Starter
Fanatic Member
Re: Excel and cross-workbook code
 Originally Posted by RobDog888
I see three ways to do it.
- Create an Excel Add-In.
- Create a dll.
- Use code to modify the macros in all workbooks
I havent done it myself for VBA but I would assume that if you create a VB Dll to do it
it would be the same. otherwise you would need the Developer version of
Office which can compile.
I think it may be easiest to use my CodeBank code to modify VBA code from VB (#3)!
You can check it out here.
HTH
All of the code is protected so code modifying code won't work. Apparently the user needs to add the addin, and this is supposed to have as little to do with excel (according to the user) as possible.
How would I go about the DLL? I've never used a non-windows API one before.
Don't pay attention to this signature, it's contradictory.
-
Dec 24th, 2004, 03:15 PM
#4
Re: Excel and cross-workbook code
I am not 100% sure, but I believe you can just create the dll in VB. Start VB
and select ActiveX Dll as the project. Then add your code and compile. In
the vba project properties of an Excel workbook, you can add the reference
to the dll. Then the wb should act like the code is all behind the wb.
I am only not sure of this because they do have a Developer version for
Office XP only and they havent put anything out for any other version. SoI
think it should work. Although if for 2003, I know they have VSTO which does
create dlls but is used with .NET
HTH
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 
-
Dec 24th, 2004, 03:28 PM
#5
Thread Starter
Fanatic Member
Re: Excel and cross-workbook code
 Originally Posted by RobDog888
I am not 100% sure, but I believe you can just create the dll in VB. Start VB
and select ActiveX Dll as the project. Then add your code and compile. In
the vba project properties of an Excel workbook, you can add the reference
to the dll. Then the wb should act like the code is all behind the wb.
I am only not sure of this because they do have a Developer version for
Office XP only and they havent put anything out for any other version. SoI
think it should work. Although if for 2003, I know they have VSTO which does
create dlls but is used with .NET
HTH
Alright, so I go in vb and make a dll then:
Write the code:
public function test as single
test = rnd*50
end function
Compile
Add it as a reference
Then in excel I write
msgbox test
?
Don't pay attention to this signature, it's contradictory.
-
Dec 24th, 2004, 03:35 PM
#6
Thread Starter
Fanatic Member
Re: Excel and cross-workbook code
nevermind, i got it. I actually have to create an instance of the class...
Wow, that's cool! 
Now, can I use code with excel commands (worksheet) in these dlls somehow?
Don't pay attention to this signature, it's contradictory.
-
Dec 24th, 2004, 03:40 PM
#7
Re: Excel and cross-workbook code
Yes, add a reference to Excel but it will be removed before you compile. Then
program in the reference object you need. Then when done change your
Excel Object declarations to late bound and remove the reference. This will
make it easier to program and also allow you to use the dll accross multiple
versions of Excel.
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 
-
Dec 24th, 2004, 03:40 PM
#8
Thread Starter
Fanatic Member
Re: Excel and cross-workbook code
For example, I want to do this:
application.enableevents = false
But i get a compile error (duh) because application isn't defined. Is there anyway to get around this?
Don't pay attention to this signature, it's contradictory.
-
Dec 24th, 2004, 04:05 PM
#9
Thread Starter
Fanatic Member
Re: Excel and cross-workbook code
Alright, next:
How do I get at a public function inside a module in the dll? Classes is easy, but I can't seem to access the modules.
Don't pay attention to this signature, it's contradictory.
-
Dec 25th, 2004, 12:48 PM
#10
Re: Excel and cross-workbook code
In the VBA Editor with the reference to your dll, use the Object Browser to see
if you can see your function in the module. If its declared as Public then it
should be visible in the OB.
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 
-
Dec 26th, 2004, 03:34 PM
#11
Thread Starter
Fanatic Member
Re: Excel and cross-workbook code
 Originally Posted by RobDog888
In the VBA Editor with the reference to your dll, use the Object Browser to see
if you can see your function in the module. If its declared as Public then it
should be visible in the OB.
They don't show up, and they are all declared public.
Don't pay attention to this signature, it's contradictory.
-
Dec 26th, 2004, 03:57 PM
#12
Re: Excel and cross-workbook code
I'm not 100% fluent at dlls, but it should be visible. What if you placed it in the class?
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 
-
Dec 27th, 2004, 11:53 AM
#13
Thread Starter
Fanatic Member
Re: Excel and cross-workbook code
 Originally Posted by RobDog888
I'm not 100% fluent at dlls, but it should be visible. What if you placed it in the class?
I tried placing it in the class, but I would have to rewrite all the functions calls to include the "class.", and the classes called by the dll would be different instances than the ones I called (inside one class another is called, so it must be declared with, etc.) I just decided that this type fo thing didn't belong inside a DLL.
Don't pay attention to this signature, it's contradictory.
-
Dec 27th, 2004, 01:24 PM
#14
Re: Excel and cross-workbook code
If a dll is no longer considered the way to go then what about the Add-In?
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 
-
Dec 29th, 2004, 09:14 PM
#15
Thread Starter
Fanatic Member
Re: Excel and cross-workbook code
 Originally Posted by RobDog888
If a dll is no longer considered the way to go then what about the Add-In?
I just realized I can include a form in the dll, and use control arrays in excel!
I'm going to stay the path of 'copy-paste' for now.
Don't pay attention to this signature, it's contradictory.
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
|