Results 1 to 7 of 7

Thread: Get excel formatting information

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Ipswich,UK
    Posts
    14

    Red face Get excel formatting information

    I'm using vb6 to extract data from an excel worksheet. Is there any way to obtain formatting information? I need individual column widths and whether text spans a number of columns.

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

    Re: Get excel formatting information

    Since there are a few questions to be answered I think this way is best.

    Usually the easiest way to find out how to access some property or method in most Office Apps is to record
    a macro and then check out the code in the VBA IDE (ALT+F11). Its usually in a Module with the date it was written in the
    header of the procedure. Then you can place the code in VB with a little translating where needed.

    Post back if you neeed more help on this.

    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 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

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Ipswich,UK
    Posts
    14

    Re: Get excel formatting information

    Yes, I agree but, in this case, I can't see how to record a macro asking for the information I need.

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

    Re: Get excel formatting information

    Ok, here is the first recorded macro. I just started a recording and adjusted a column's width.
    VB Code:
    1. Sub Macro1()
    2. ' Macro1 Macro
    3. ' Macro recorded 2/7/2005 by VB/Office Guru
    4.     Columns("C:C").ColumnWidth = 20
    5.     Columns("E:E").ColumnWidth = 6
    6. End Sub
    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

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

    Re: Get excel formatting information

    Ok, now this one is a little different. I had to go into the Formatting menu
    and click Cells... then check Merge cells after I selected three cells that I
    had typed some text into. I typed the text into the first cell and continued
    typing until it reached the third cell.

    VB Code:
    1. Sub Macro2()
    2. ' Macro2 Macro
    3. ' Macro recorded 2/7/2005 by VB/Office Guru
    4.     Range("A4").Select
    5.     ActiveCell.FormulaR1C1 = "Testing the macro to record spaned cell info."
    6.     Range("A4:C4").Select
    7.     With Selection
    8.         .HorizontalAlignment = xlGeneral
    9.         .VerticalAlignment = xlBottom
    10.         .WrapText = False
    11.         .Orientation = 0
    12.         .AddIndent = False
    13.         .IndentLevel = 0
    14.         .ShrinkToFit = False
    15.         .ReadingOrder = xlContext
    16.         .MergeCells = True
    17.     End With
    18. End Sub
    So these two macros will show you how to access the properties/methods
    to determine the formatting on a spreadsheet.



    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 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

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    Ipswich,UK
    Posts
    14

    Re: Get excel formatting information

    THanks very much for taking so much trouble to help me. I'll get working along these lines.

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

    Re: Get excel formatting information

    Not a problem. Glad to help.

    Ps, dont forget to Resolve your thread
    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