|
-
Apr 11th, 2007, 04:56 PM
#1
Thread Starter
Hyperactive Member
Excel Questions
Anyone that follows this forum has figured out that I am doing a project utilizing Excel. I have a few question and figured that I would throw them in one post.
1. I've seen a few posts from RobDog that mentions using
Code:
moApp = DirectCast(CreateObject("Excel.Application"), Excel.Application)
Does this eliminate the need to use a reference? I'm afraid that if I specify a specific reference that I will encounter Excel version problems in the future.
2. I have a template that I'm opening like this
Code:
oApp.Workbooks.Open(Filename:=data.fileIn)
Now I want to fill this template with data from a CSV file. What is the best way to import this data? My initial plan was to create temp worksheet to place the data, copy and paste data to the worksheet with formating then delete the temp worksheet. It seems like there should be an easier way.
3. Is there an easy way to create a new chart and place it behind the other charts? I'm doing this but it seems a little cluncky
Code:
With oCht
.Move(, oWb.Worksheets(oWb.Worksheets.Count))
.Move(, oWb.Charts(oWb.Charts.Count))
End With
-
Apr 11th, 2007, 07:39 PM
#2
Re: Excel Questions
If you don't have a reference then you wouldn't be able to specify this part:
Code:
moApp = DirectCast(CreateObject("Excel.Application"), Excel.Application)
I'm no Office guru but I think that the convention when targeting multiple versions of an Office application is to add the reference so you have Intellisense while you develop, then when you're done you remove the reference and go through and fix all the errors that result by enabling late-binding and changing all the Office-specific types to Object. You'd then have to load the appropriate Office library at run time.
-
Apr 12th, 2007, 12:58 AM
#3
Re: Excel Questions
Yes, by having a reference you are using Early Binding and the other reason using the DirectCast is to conform with the Option Strict On declaration which helps reduce type casting errors and other stuff.
If you want to Late Bind so you can support multiple versions of Excel then you may not be able to use the Office Primary Interop Assemblies (link in my sig) as only 2002 and 2003 are supported with them. If your supporting Excel 97 or 2000 then you will need to develop on a system with that version etc. to make sure you are using functions and methods thgat are supported.
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
|