Results 1 to 4 of 4

Thread: [RESOLVED] Converting from BVA to VB6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    79

    Resolved [RESOLVED] Converting from BVA to VB6

    Hi I need to convert the format of two columns in excel. Time and Date. I recorded a macro and this is the BVA code I get.

    Code:
        Columns("B:B").Select
        Selection.NumberFormat = "h:mm;@"
        Columns("A:A").Select
        Selection.NumberFormat = "m/d/yy;@"
    Now I need to convert it to VB6. Can you help me? I try it several times but I could not get it. See below
    Code:
     'oXLsheet.Range(Columns).Select
        oXLsheet.Columns("B:B").Select
        oXLsheet.Columns.NumberFormat = "h:mm;@"  
        oXLsheet.Columns("A:A").Select    
        oXLsheet.Columns.NumberFormat = "m/d/yy;@"
    Thanks

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

    Re: Converting from BVA to VB6

    Did you instanciate oXLsheet? Whats the rest of your code look like that opens the workbook? Any error messages and what does the cell format do if its not correct?
    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

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Converting from BVA to VB6

    The first step to take is remove .Select and Selection, so this:
    Code:
        Columns("B:B").Select
        Selection.NumberFormat = "h:mm;@"
    becomes this:
    Code:
        Columns("B:B").NumberFormat = "h:mm;@"
    (this will work around your mistake - you didn't specify which Columns to set the NumberFormat on)

    ..and then, make it safe for VB by prefixing your sheet object, eg:
    Code:
        oXLsheet.Columns("B:B").NumberFormat = "h:mm;@"

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    79

    Re: Converting from BVA to VB6

    That did it. Thank you Si_The_Geek!

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