Results 1 to 23 of 23

Thread: VBA desparation!!!!

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    VBA desparation!!!!

    I have this piece of code that is ran from within Access. It opens a series of .xls files and does some formatting. My biggest problem right now is that I'm trying to hide a column and I keep getting the error message:

    "Object doesn't support this property or method"

    It happens on the following line of code:

    Code:
                    With myXLWrkSheet
                        .Select
                        .Rows("1:1").Font.Bold = True
                        .Columns("A").Insert
                        .Range("A2", .Range("B65536").end(xlUp).Offset(0, -1)).FormulaR1C1 _
                         = "=HYPERLINK(RC[14],RC[1])"
                        .Selection.EntireColumn.Hidden = True   ////// Errors out here \\\\\\\
                        .Columns("A:V").AutoFit
                    End With
    Here is the whole function below:

    Code:
    Public Function formatXLFiles()
        Dim fso                 As New FileSystemObject
        Dim myXLApp             As Object
        Dim myXLWrkBook         As Object
        Dim myXLWrkSheet        As Object
        Dim filepath            As String
        Dim f                   As Folder
        Dim fj                  As Files
        Dim f2                  As File
        Dim fc                  As Folders
        Dim aHit                As Integer
        Dim Selection           As Variant
        Dim numRows, numCols    As Integer
        
        Const xlToRight = -4161
        Const xlUnderLineStyleNone = -4142
        Const xlAutomatic = -4105
        Const xlDown = -4121
        Const xlUp = -4162
        Const xlToLeft = -4159
        
        filepath = "C:\qatools\FieldReports"
        
        If fso.FolderExists(filepath) Then
            Set f = fso.GetFolder(filepath)
            Set fc = f.SubFolders
            Set fj = f.Files
    
            For Each f2 In fj
                Set myXLApp = CreateObject("Excel.Application")
                Set myXLWrkBook = myXLApp.Workbooks.Open(f2)
                
                Set myXLWrkSheet = myXLWrkBook.Worksheets(1)
                myXLWrkBook.Application.Windows(1).Visible = True
                
                With myXLWrkSheet
                    With .Rows("1:1").Font
                        .Name = "MS Sans Serif"
                        .Bold = True
                        .Size = 8.5
                    End With
                    .Columns("A:V").AutoFit
                End With
                
                If f2 Like "*DETAIL*" Then
                    With myXLWrkSheet
                        .Select
                        .Rows("1:1").Font.Bold = True
                        .Columns("A").Insert
                        .Range("A2", .Range("B65536").end(xlUp).Offset(0, -1)).FormulaR1C1 _
                         = "=HYPERLINK(RC[14],RC[1])"
                        .Selection.EntireColumn.Hidden = True
                        .Columns("A:V").AutoFit
                    End With
                End If
                myXLWrkBook.Close True
                Set myXLWrkSheet = Nothing
                Set myXLWrkBook = Nothing
            Next
        End If
        
        MsgBox "Processing Complete!"
        End
    End Function
    I'm really getting desparate with this...PLEASE SOMEONE HELP!!!!!

    Thanks,
    Blake
    Last edited by blakemckenna; May 27th, 2005 at 10:04 AM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Any ideas anyone?

  3. #3
    Addicted Member
    Join Date
    Jan 2003
    Posts
    163

    Re: VBA desparation!!!!

    which column are you trying to hide, i don't see a specific column selected

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    I'm actually trying to hide 2 columns; column 2 and the last column (although I'm not sure how to reference the last column).

    Any ideas?

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VBA desparation!!!!

    as i don't use access i tried your code from vb, i got the same error when trying to hide the column, but i was able to use

    .Columns("H").Hidden = True

    see if this works for you

    pete

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Wes,

    Unfortunately that didn't work. I'm new to VBA so with what I know and a quarter you might be able to buy a candy bar...hehe

    I'm open to new suggestions though!!!!

    Thanks,
    Blake

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

    Re: VBA desparation!!!!

    Its the same issue that we solved yesterday. The .Selection object doesnt exist for the object.
    Try just Selection.EntireColumn.Hidden = True without the "." before Selection.
    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

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Rob,

    It didn't work. Gave me "Object Required" error.

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

    Re: VBA desparation!!!!

    Oops, sorry missed something.

    after you add the hyperlink, you need to select the column so you can hide it using the Selection Object.

    VB Code:
    1. With myXLWrkSheet
    2.         .Select
    3.         .Rows("1:1").Font.Bold = True
    4.         .Columns("A").Insert
    5.         .Range("A2", .Range("B65536").End(xlUp).Offset(0, -1)).FormulaR1C1 _
    6.          = "=HYPERLINK(RC[14],RC[1])"
    7.         .Columns("A:A").Select
    8.         Selection.EntireColumn.Hidden = True '  ////// Errors out here \\\\\\\
    9.         .Columns("A:V").AutoFit
    10.     End With
    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

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Rob,

    It errors out on me with an "Object Required" error. It happens on the

    Selection.EntireColumn.Hidden = True

    line of code.



    Code:
        With myXLWrkSheet
            .Select
            .Rows("1:1").Font.Bold = True
            .Columns("A").Insert
            .Range("A2", .Range("B65536").End(xlUp).Offset(0, -1)).FormulaR1C1 _
             = "=HYPERLINK(RC[14],RC[1])"
            .Columns("A:A").Select
            Selection.EntireColumn.Hidden = True '  ////// Errors out here \\\\\\\
            .Columns("A:V").AutoFit
        End With

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

    Re: VBA desparation!!!!

    Thats weird because it ran fine for me on a test workbook.
    Try it in a new blank workbook.
    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

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Rob,

    Are you running this code from within an Access DB? That's how I am running this app...from within Access.

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

    Re: VBA desparation!!!!

    Here is my test from within an Access module.
    VB Code:
    1. Private Sub Test8()
    2.     Dim oApp As Excel.Application
    3.     Dim oWB As Excel.Workbook
    4.    
    5.     Set oApp = GetObject(, "Excel.Application")
    6.     Set oWB = oApp.Workbooks(1)
    7.    
    8.     Dim myXLWrkSheet As Excel.Worksheet
    9.     Set myXLWrkSheet = oWB.Sheets(1)
    10.     With myXLWrkSheet
    11.         .Select
    12.         .Rows("1:1").Font.Bold = True
    13.         .Columns("A").Insert
    14.         .Range("A2", .Range("B65536").End(xlUp).Offset(0, -1)).FormulaR1C1 _
    15.          = "=HYPERLINK(RC[14],RC[1])"
    16.         .Columns("A:A").Select
    17.         .Columns("A:A").EntireColumn.Hidden = True
    18.         .Columns("A:V").AutoFit
    19.     End With
    20. End Sub
    This was still part of the previous issue with the Selection object. Access has one and Excel does not.
    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

  14. #14

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Let me give this a shot Rob...

    Thanks!!!

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Sorry Rob,

    It didn't fly either.

    Blake

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

    Re: VBA desparation!!!!

    I dont know what to tell you. I recreated the enviroment and got it to work. What was the error, if any?
    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

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    There was no error anymore....it just didn't hide the columns.

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

    Re: VBA desparation!!!!

    Step through the code (Press F8). It may be a speed issue.
    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

  19. #19

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Hold your breath brother.....I think it just worked. I'm running another test right now.

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Rob,

    You da man brother. It finally worked. I don't know why it didn't work before but for some reason it's flyin' now. Thanks so much for your help!!!!

    Using your .Columns object...can I set the Autofilter for columns as well and if so, what is the syntax for that?

    Thanks again,

    Blake

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    False alarm Rob.

    It don't work!

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

    Re: VBA desparation!!!!

    Did it just not hide the column or error? During run more or stepping through (F8)?

    Here is an example from the help file on the AutoFiler object. I havent used it before so dont know if I can help you that much on it.,

    VB Code:
    1. Set w = Worksheets("Crew")
    2. w.AutoFilterMode = False
    3. For col = 1 To UBound(filterArray(), 1)
    4.     If Not IsEmpty(filterArray(col, 1)) Then
    5.         If filterArray(col, 2) Then
    6.             w.Range(currentFiltRange).AutoFilter field:=col, Criteria1:=filterArray(col, 1), _
    7.                     Operator:=filterArray(col, 2), Criteria2:=filterArray(col, 3)
    8.         Else
    9.             w.Range(currentFiltRange).AutoFilter field:=col, Criteria1:=filterArray(col, 1)
    10.         End If
    11.     End If
    12. Next
    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

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: VBA desparation!!!!

    Hey Rob,

    Just wanted to let you know....your code did work. For some reason when I made the changes to my code they didn't take and it reverted back to the old code. I caught it and replaced it with your code and it works great. I will try the Filter code tomorrow.

    Thanks for all you help bro,

    Blake

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