+ Reply to Thread
Results 1 to 6 of 6

I run a macro which changes attributes of a cell and then cannot restore gridlines

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    I run a macro which changes attributes of a cell and then cannot restore gridlines

    (...cannot see the gridlines -- they're there but somehow hidden).

    I run this macro across my workbook, it changes cell properties, and then I am unable to see gridlines. When I use excel's ribbon in the program to turn off all gridlines and turn on all gridlines, there is no change. Here is what I mean by gridlines: https://support.office.com/en-us/art...a-b26f4adc3fb4

    Every cell this code loops over results in a hidden gridline. MsgBox(C.Application.ActiveWindow.DisplayGridlines) displays "True" so there is no point to running code:
    WS.Activate
    ActiveWindow.DisplayGridlines = True

    That leads me to believe there is an attribute of each Cell: C that is changed; but I don't know what attribute is changed.

    I wish there was a way to list all attributes of a cell so I can more easily figure this out, but an Excel 2007 machine I have doesn't have a TypeLib.dll and neither does mine so I can't follow the suggestions of others who have gone down that path (if I'm understanding that correctly)

    Here is my macro that unintentionally hides gridlines, despite the fact that MsgBox(C.Application.ActiveWindow.DisplayGridlines) is True, where C is ANY cell in the workbook -- but now that I think about it, perhaps that would always be True or that would always be False for any cell in the same worksheet... no matter, another lesson for another day.
    Sub RemovingCFButNotEffects()
        'Removing Conditional Formats But Not The Effects
        '------------------------------------------------
        Dim Rng As Range, R As Range, C As Range
        Dim WS As Worksheet
        Dim LastRow As Long, LastColumn As Long, LastColumnOfRow As Long
        Dim C_LineStyle As Double, C_Weight As Double
        
        Application.ScreenUpdating = False
            
        
        For Each WS In ThisWorkbook.Worksheets
            Set Rng = WS.Range(WS.UsedRange.Address)
            LastRow = Rng.RowS.Count
            LastColumn = Rng.Columns.Count
            For Each R In Rng.RowS
                LastColumnOfRow = R.Cells(R.Row, LastColumn).End(xlToLeft).Column
                For Each C In R.Cells
                    With C
                        If .Column <= LastColumnOfRow Then
                            .Interior.Color = .DisplayFormat.Interior.Color
                            .Font.FontStyle = .DisplayFormat.Font.FontStyle
                            .Font.Color = .DisplayFormat.Font.Color
                            .FormatConditions.Delete
                        Else
                            Exit For
                        End If
                    End With
                Next C
            Next R
            WS.Activate
            ActiveWindow.DisplayGridlines = True
        Next WS
        Application.ScreenUpdating = True
        
        MsgBox ("The Conditional Formats In The Range " & Rng.Address & vbCrLf & "Has Been Removed But Not The Effects")
    End Sub
    If someone has the dll necessary to run the following code, I would appreciate seeing the results!
    ' PGC Jun 2009
    ' Lists the enumerators of a library
    Sub ListConstants()
    Dim oTLIApplication As TLI.TLIApplication
    Dim oTLITypeLibInfo As TLI.TypeLibInfo
    Dim oTypeInfo As TLI.TypeInfo
    Dim oTLIMember As TLI.MemberInfo
    Dim sLib As String
    Dim lType As Long
    Dim WS As Worksheet
     
    sLib = "C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.exe" 'for excel 365
    'sLib = "c:\program files\microsoft office2007\office12\excel.exe" ' for excel 2007
    'sLib = "c:\program files\microsoft office2k\office\excel9.olb"        ' for excel 2000
    
    Set oTLIApplication = New TLI.TLIApplication
    Set oTLITypeLibInfo = oTLIApplication.TypeLibInfoFromFile(sLib)
    Set WS = ThisWorkbook.Worksheets("Sheet1")
    With WS
        For Each oTypeInfo In oTLITypeLibInfo.TypeInfos
            If oTypeInfo.TypeKind = TKIND_ENUM Then
                For Each oTLIMember In oTypeInfo.Members
                    lType = lType + 1
                    .Range("A" & lType) = oTypeInfo.Name        ' enumerator
                    .Range("B" & lType) = oTLIMember.Name       ' constant
                    .Range("C" & lType) = oTLIMember.Value      'value
                Next oTLIMember
            End If
        Next oTypeInfo
    End With
    End Sub
    Last edited by joe31623; 01-09-2016 at 01:34 AM.
    <---If my answer helped, please click *

  2. #2
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: I run a macro which changes attributes of a cell and then cannot restore gridlines

    Hi

    Not sure if this is the problem, and i have no idea what the dll is doing but ...

    If .Column <= LastColumnOfRow Then
             .Interior.Color = .DisplayFormat.Interior.Color '<- what color is this returning
             .Font.FontStyle = .DisplayFormat.Font.FontStyle
             .Font.Color = .DisplayFormat.Font.Color
             .FormatConditions.Delete
    Else
    it maybe that the gridlines are hidden by the background color, also in the view pane on the ribbon can you check and uncheck the gridlines, have you also checked the color of the gridlines in the options, have you also tried setting the fill to 'None'?

    Just throwing some ideas around, give them a try.

    Thanks
    Paul Smith

  3. #3
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: I run a macro which changes attributes of a cell and then cannot restore gridlines

    Paul,

    Good suggestion. When I ran that code with modification:
    If .Column <= LastColumnOfRow Then
         MsgBox(.Interior.Color)
         MsgBox(.DisplayFormat.Interior.Color)
    '/.
    '/.
    '/.
    I got the same value: 16777215 (for cells with no interior color), in both Message Boxes, which leads me to believe it's not being changed. Just to verify I'm seeing that value change with color, I ran the code after manually setting the interior color of one cell to yellow and got 65535 for both values: .Interior.Color and .DisplayFormat.Interior.Color.

    The purpose of the macro is to go through the workbook, set all colored cells that are colored based on conditional formatting to the color they are (regardless of conditional formatting) and then remove the conditional formatting.
    Last edited by joe31623; 01-09-2016 at 01:00 AM.

  4. #4
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: I run a macro which changes attributes of a cell and then cannot restore gridlines

    if you set a color using

    Interior.Color = 0 'or any number, it always gets filled and hence the gridlines wont be shown
    
    Interior.Colorindex = xlNone 'which is -4142 which should remove any fill
    Try this

    Thanks
    Paul S.

  5. #5
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: I run a macro which changes attributes of a cell and then cannot restore gridlines

    THANKS, Paul!

    That was exactly what I needed.

  6. #6
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: I run a macro which changes attributes of a cell and then cannot restore gridlines

    No Problem

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to Get File Attributes
    By Brawnystaff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-25-2015, 07:12 PM
  2. Macro to get file attributes - length
    By Brawnystaff in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2015, 12:51 PM
  3. In Excel, gridlines won't print--File,PageSetup,Sheet,Gridlines--
    By 4most in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-10-2006, 03:29 AM
  4. Some gridlines missing - How to restore
    By Oliver Costich in forum Excel General
    Replies: 2
    Last Post: 03-29-2006, 02:25 PM
  5. how to restore worksheet's gridlines &amp;amp; attributes
    By xppuser in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-15-2006, 01:35 PM
  6. Macro (attributes?)
    By Brad in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2005, 11:25 AM
  7. [SOLVED] Restore Gridlines
    By JayVee in forum Excel General
    Replies: 1
    Last Post: 03-03-2005, 09:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1