Results 1 to 3 of 3

Thread: Excel Questions

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width