Results 1 to 37 of 37

Thread: [RESOLVED] Select Method of Range Class failed Error?

  1. #1

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

    Resolved [RESOLVED] Select Method of Range Class failed Error?

    I keep getting the above error message on the following line of code:

    Code:
          myXLWrkSheet.Columns("A:A").Select
    Here is the rest of my code so it makes more sense.

    Code:
                If aHit > 0 Then
                    Set myXLWrkBook = GetObject(f2)
    
                    Set myXLWrkSheet = myXLWrkBook.Worksheets(1)
                    numCols = myXLWrkSheet.UsedRange.Columns.count
                    numRows = myXLWrkSheet.UsedRange.rows.count
                    strCol = "A" & numCols
                    
                    myXLWrkSheet.Columns("A:V").Select  ////// Error Msg Occurs here  \\\\\\\
                    myXLWrkSheet.Columns("A:V").EntireColumn.AutoFit
                    myXLWrkSheet.Rows("1:1").Select
                
                    With myXLWrkSheet
                        .Name = "MS Sans Serif"
                        .Size = 8.5
                    End With
    
                    myXLWrkSheet.Selection.Font.Bold = True
                    myXLWrkSheet.Columns("A:A").Select
                    myXLWrkSheet.Selection.Insert Shift:=xlToRight
                    myXLWrkSheet.Range("A2").Select
                    myXLWrkSheet.ActiveCell.FormulaR1C1 = "=HYPERLINK(RC[14],RC[1])"
                    myXLWrkSheet.Selection.Copy
                    myXLWrkSheet.Range("B2").Select
                    myXLWrkSheet.Selection.End(xlDown).Select
                    myXLWrkSheet.Selection.End(xlToLeft).Select
                    myXLWrkSheet.Range("A3:A4").Select
                    myXLWrkSheet.Range("A4").Activate
                    myXLWrkSheet.ActiveSheet.Paste
                Else
                    myXLWrkSheet.Columns("A:V").Select
                    myXLWrkSheet.Columns("A:V").EntireColumn.AutoFit
                    myXLWrkSheet.rows("1:1").Select
                
                    With myXLWrkSheet
                        .Name = "MS Sans Serif"
                        .Size = 8.5
                    End With
                    
                    myXLWrkSheet.Range("A" & startrow & ":A" & stoprow).Copy
                    myXLWrkSheet.Columns("A:V").Select
                    myXLWrkSheet.Columns("A:V").EntireColumn.AutoFit
                    myXLWrkSheet.rows("1:1").Select
                    myXLWrkSheet.Selection.Font.Bold = True
                End If

  2. #2

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

    Re: Select Method of Range Class failed Error?

    Does anyone have any ideas???? I really need to get this code out by end-of-day.

    Thanks,

    Blake

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

    Re: Select Method of Range Class failed Error?

    Could there be something to do with your specific sheet since it works.

    Also, is that sheet the active sheet? Try selecting the sheet first then make your selection.

    VB Code:
    1. Sheets(1).Select
    2.     Sheets(1).Columns("A:V").Select
    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

  4. #4

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

    Re: Select Method of Range Class failed Error?

    Rob,

    I'll give that a try...

    Thanks,

    Blake

  5. #5

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

    Re: Select Method of Range Class failed Error?

    Rob,

    It's not liking any of this code. What am I doing wrong?

    Blake

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

    Re: Select Method of Range Class failed Error?

    Test it in a new workbook. If it works in the new one then you must have applied something to it that it doesnt like.
    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

  7. #7

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

    Re: Select Method of Range Class failed Error?

    Rob,

    I tried using this code from within a new Access DB. The code accessed the same XLS file and still gave me the same error. Should I try a completely blank worksheet?

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

    Re: Select Method of Range Class failed Error?

    Yes, and is the workbook visible when you were testing?
    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

  9. #9

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

    Re: Select Method of Range Class failed Error?

    No....the workbook is not visible...how do I do that?

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

    Re: Select Method of Range Class failed Error?

    I'm 99.9% sure that it needs to be visible in order to make any kind of selection.
    You can do an ..

    VB Code:
    1. myXLApp.Visible = True
    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

  11. #11

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

    Re: Select Method of Range Class failed Error?

    I figured that one out Rob but it still didn't work. I don't understand...this is really weird!!!

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

    Re: Select Method of Range Class failed Error?

    Does it work in a new workbook? Could it be your installation if it doesnt work in a new visible one.
    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

  13. #13

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

    Re: Select Method of Range Class failed Error?

    Rob,

    It doesn't work in a new workbook. I can I email you Function. I have certain lines highlighted with colors that might explain things better.

    Thanks,

    Blake

  14. #14
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Select Method of Range Class failed Error?

    Maybe the sheet isn't active? Try: myXLWrkSheet.Activate before selecting the column.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  15. #15
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Select Method of Range Class failed Error?

    I'm fairly certain that is the answer ... there is no provision in your code to assure that the sheet is active, and it must be the active sheet to perform selections on it. The selected area does not need to be visible! I learned that in the "School of Hard Knocks"!
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  16. #16

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

    Re: Select Method of Range Class failed Error?

    Could you please show me the code necessary to acheive this?

    Thanks,

    Blake

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

    Re: Select Method of Range Class failed Error?

    Quote Originally Posted by Webtest
    Maybe the sheet isn't active? Try: myXLWrkSheet.Activate before selecting the column.
    Doh! That should take care of the selection issue. I was thinking Visible when I should have thought Active.
    Also, I got this for the autofit line - myXLWrkSheet.Columns("A:V").AutoFit
    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

  18. #18

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

    Re: Select Method of Range Class failed Error?

    I'll give it a try....

    thanks!

  19. #19

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

    Re: Select Method of Range Class failed Error?

    Still didn't work...

    Here's the revised code:

    Code:
        If fso.FolderExists(filepath) Then
            Set f = fso.GetFolder(filepath)
            Set fc = f.SubFolders
            Set fj = f.Files
    
            For Each f2 In fj
                Set myXLWrkBook = GetObject(f2)
                Set myXLWrkSheet = myXLWrkBook.Worksheets(1)
                myXLWrkSheet.Activate     /////////// Still not working with this line of code \\\\\\\\\\\\
                
                With myXLWrkSheet
                    With .Rows("1:1").Font
                        .Name = "MS Sans Serif"
                        .Bold = True
                        .Size = 8.5
                    End With
                End With
                
                aHit = InStr(f2, "DETAIL")
                
                If aHit > 0 Then
                    numCols = myXLWrkSheet.UsedRange.Columns.count
                    strCol = "A" & numCols
                    
    '                myXLWrkSheet.active = True
                    'myXLWrkSheet.Columns("A:V").Select
                    myXLWrkSheet.Columns("A:V").EntireColumn.AutoFit
                    'myXLWrkSheet.Rows("1:1").Select
                    
                    
                    myXLWrkSheet.Selection.Font.Bold = True
                    myXLWrkSheet.Columns("A:A").Select
                    myXLWrkSheet.Selection.Insert Shift:=xlToRight
                    myXLWrkSheet.Range("A2").Select
                    myXLWrkSheet.ActiveCell.FormulaR1C1 = "=HYPERLINK(RC[14],RC[1])"
                    myXLWrkSheet.Selection.Copy
                    myXLWrkSheet.Range("B2").Select
                    myXLWrkSheet.Selection.end(xlDown).Select
                    myXLWrkSheet.Selection.end(xlToLeft).Select
                    myXLWrkSheet.Range("A13:A14").Select
                    myXLWrkSheet.Range("A14").Activate
                    myXLWrkSheet.Range(Selection, Selection.end(xlUp)).Select
                    myXLWrkSheet.Range("A2:A14").Select
                    myXLWrkSheet.Range("A14").Activate
                    myXLWrkSheet.ActiveSheet.Paste
                End If
    
                myXLWrkBook.Save
                myXLWrkBook.Close
                Set myXLWrkSheet = Nothing
                Set myXLWrkBook = Nothing
                aHit = 0
            Next
        End If

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

    Re: Select Method of Range Class failed Error?

    VB Code:
    1. 'It should be ...
    2. myXLWrkSheet.Activate
    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

  21. #21

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

    Re: Select Method of Range Class failed Error?

    I tried that Rob and it still doesn't work. I still get the same error messages. I don't know what to do...

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

    Re: Select Method of Range Class failed Error?

    I think it may have something to do with the way your instanciating the object.
    VB Code:
    1. Set myXLWrkBook = GetObject(f2)
    2. 'Try instead
    3. Set myXLApp = CreateObject("Excel.Application")
    4. Set myXLWrkBook = myXLApp.Workbooks.Open(f2)
    5. '...
    6. '...
    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
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Select Method of Range Class failed Error?

    For heaven's sake, put "Option Strict" as the very top line of your module. If it breaks anything, that is GOOD, because broken things were being hidden!
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  24. #24

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

    Re: Select Method of Range Class failed Error?

    I get an "Expected: Base or Compare or Explicit or Private" error when I try to insert "Option Strict".

    Once again...here's what I have so far....

    Code:
            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
                End With
                
                aHit = InStr(f2, "DETAIL")
                
                If aHit > 0 Then
                    numCols = myXLWrkSheet.UsedRange.Columns.count
                    strCol = "A" & numCols
                    
                    myXLWrkSheet.Columns("A:V").EntireColumn.AutoFit
                    myXLWrkSheet.Columns("A:V").Select
                    myXLWrkSheet.Rows("1:1").Select
                    
    '                myXLWrkSheet.Selection.Font.Bold = True
                    myXLWrkSheet.Columns("A:A").Select
    '                myXLApp.myXLWrkSheet.Selection.Insert Shift:=xlToRight
                    myXLWrkSheet.Range("A2").Select
    '                myXLWrkSheet.ActiveCell.FormulaR1C1 = "=HYPERLINK(RC[14],RC[1])"
    '                myXLWrkSheet.Selection.Copy
                    myXLWrkSheet.Range("B2").Select
    '                myXLWrkSheet.Selection.End(xlDown).Select
    '                myXLWrkSheet.Selection.End(xlToLeft).Select
                    myXLWrkSheet.Range("A13:A14").Select
                    myXLWrkSheet.Range("A14").Activate
    '                myXLWrkSheet.Range(Selection, Selection.End(xlUp)).Select
                    myXLWrkSheet.Range("A2:A14").Select
                    myXLWrkSheet.Range("A14").Activate
    '                myXLWrkSheet.ActiveSheet.Paste
                End If
                
                myXLWrkBook.Save
                myXLWrkBook.Close
                Set myXLWrkSheet = Nothing
                Set myXLWrkBook = Nothing
            Next
    The only thing not working now are the lines of code that are commented out.

    I am getting closer!!!!!

    Thanks to all who are helping!

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

    Re: Select Method of Range Class failed Error?

    You can not use "Option Strict" in VB6/VBA. Its only for .NET
    You may be thinking of "Option Explicit" for VB6/VBA.

    So it was the GetObject that was causing some of the issues.
    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

  26. #26

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

    Re: Select Method of Range Class failed Error?

    Who knows....all I know is that it didn't fix it completely. I just don't know VBA well enough to figure this out on my own.

    I'll stick with straight VB anyday....HAHA

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

    Re: Select Method of Range Class failed Error?

    Here's the fix...
    VB Code:
    1. Selection.Font.Bold = True
    2. 'Repeat syntax for other .Selection lines of code
    The Selection object is an Application level object and not a sheet level object.
    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

  28. #28
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Select Method of Range Class failed Error?

    Regarding the "Option Explicit": My humble apologies ... I got my forums mixed up. I normally lurk on the .Net forum, and I was in a hurry to get home last night.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

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

    Re: Select Method of Range Class failed Error?

    No worries. I have had similar things happen when switching between VB6/VB.NET/VBA/...

    Blake, I will be out for a few hours, but I think my last post should take care of the rest of the errors.
    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

  30. #30

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

    Re: Select Method of Range Class failed Error?

    Ok guys,

    I've almost got this thing working. I have also been talking to a VBA guru from another forum. They almost have this app doing what I want it to do. However, the app is creating 2 hyperlinks in some files when it should only be creating 1. I believe this is where variables come into play using the "Range" object but I don't know how to program it. I also need to hide the target column of the hyperlink as well as the "Friendly Name" column (which will always be in Column 2).

    Anyway, here is the current code that I have to date.

    Code:
            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
                    .Columns("A:V").AutoFit
                    With .Rows("1:1").Font
                        .Name = "MS Sans Serif"
                        .Bold = True
                        .Size = 8.5
                    End With
                End With
                
                If f2 Like "*DETAIL*" Then
                    numCols = myXLWrkSheet.UsedRange.Columns.count
                    With myXLWrkSheet
                        .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:V").AutoFit
                        .Selection.EntireColumn.Hidden = True
                    End With
                End If
                myXLWrkBook.Close True
                Set myXLWrkSheet = Nothing
                Set myXLWrkBook = Nothing
            Next
    If anyone can shed light on this...I'd be grateful. By the way....the responses from this orher forum....I have to pay for. So...needless to say, free help is much better.

    Thanks again for your help,

    Blake
    Last edited by blakemckenna; May 26th, 2005 at 01:34 PM.

  31. #31
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Select Method of Range Class failed Error?

    You are hiding a column based on a selected range (highlighted on the sheet):

    myXLWrkSheet.Selection.EntireColumn.Hidden = True

    ... but you have never set the selection (in the code that is shown). Either be sure to select the range you want to hide:

    myXLWrkSheet.<Range object>.Select

    OR - hide a range object instead of a selected range:

    myXLWrkSheet.<Range object>.EntireColumn.Hidden = True

    Immediately before the following line:
    .Range("A2", .Range("B65536").End(xlUp).Offset(0, -1)).FormulaR1C1 _
    = "=HYPERLINK(RC[14],RC[1])"

    Put a temporary diagnostic popup and see if it makes any sense:
    Code:
    'TEST TEST TEST TEST
    myXLWrkSheet.Range("A2", .Range("B65536").End(xlUp).Offset(0, -1)).Select
    MsgBox (myXLWrkSheet.Range("A2", .Range("B65536").End(xlUp).Offset(0, -1)).Address)
    'END TEST
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  32. #32
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Select Method of Range Class failed Error?

    ... and what on Earth are you trying to accomplish with this?

    myXLWrkSheet.Range("A2", .Range("B65536").End(xlUp).Offset(0, -1))
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  33. #33

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

    Re: Select Method of Range Class failed Error?

    Web,

    I have no idea exactly what this code is doing. All I know is that I need to create a hyperlink in Column 1, assign it the same heading as in Column 2, and then hide the Target Column and "Friendly Name" Column.

    The "Friendly Name" column will always be in Column 2, however, the Target Column varies in it's location.

    Can ya help???

    God Bless ya,

    Blake

  34. #34
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Select Method of Range Class failed Error?

    You need to hire a programmer. Sorry - I've got my own work to do right now.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  35. #35

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

    Re: Select Method of Range Class failed Error?

    Ok bro, I understand....thanks for your help and input.

    Have a great day!!!

    Blake

  36. #36
    New Member
    Join Date
    Oct 2012
    Posts
    1

    Re: Select Method of Range Class failed Error?

    Realise this is a pretty old thread, but its the first hit on Google so thought I'd share my solution in case it helps anyone else...

    The issue here may have been that the Macro was defined as private sub (should just be plain old sub), or it was written in an object other than Worksheet1.

    'Global' macros should be placed in a module (this was my issue... only took about 3 hours to figure it out )

  37. #37

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

    Re: Select Method of Range Class failed Error?

    This thread is so old I don't even remember opening it. I will close this immediately...
    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