+ Reply to Thread
Results 1 to 11 of 11

Run-time error '-2147417848' Method 'AddFromString'

Hybrid View

Roundsy Run-time error '-2147417848'... 09-16-2024, 10:18 AM
mjr veverka Re: Run-time error... 09-16-2024, 12:41 PM
Roundsy Re: Run-time error... 09-17-2024, 05:03 AM
ByteMarks Re: Run-time error... 09-17-2024, 05:10 AM
Roundsy Re: Run-time error... 09-17-2024, 08:53 AM
ByteMarks Re: Run-time error... 09-17-2024, 09:08 AM
Roundsy Re: Run-time error... 09-17-2024, 10:19 AM
romperstomper Re: Run-time error... 09-17-2024, 10:30 AM
Roundsy Re: Run-time error... 09-18-2024, 05:12 AM
romperstomper Re: Run-time error... 09-18-2024, 05:28 AM
Roundsy Re: Run-time error... 09-20-2024, 10:27 AM
  1. #1
    Registered User
    Join Date
    09-16-2024
    Location
    Stafford, England
    MS-Off Ver
    2016
    Posts
    6

    Run-time error '-2147417848' Method 'AddFromString'

    Hello
    I am new to VBA and this forum and need a little help please.
    I am supporting users that have hundreds of Excel files that upload to Oracle database using VB and we have recently moved servers so the DB name / URL / SID has changed.
    To make it easy for users I create the following macro which works perfect for me using Excel 2016 but not for another user using Excel 2010 so maybe this is a simple case of change in VB syntax.

    Sub UpdateVBA()
    ' *** Update VBA ***
        Dim component As Object
        For Each component In ActiveWorkbook.VBProject.VBComponents
                Dim module As Object
                Set module = component.CodeModule
               If module.CountOfLines > 0 Then
                           Dim moduleText As String
                moduleText = module.Lines(1, module.CountOfLines)
                moduleText = Replace(moduleText, "//ebseprod.nch.com:443/", "//eurprod.nch.com:443/")
                
                moduleText = Replace(moduleText, "C2039321.EBSEPROD", "NCHEBSDBS151.NCH.COM.EURPROD")
                moduleText = Replace(moduleText, "EBSEPROD", "EURPROD")
                moduleText = Replace(moduleText, "ebseprod", "eurprod")
    
                module.DeleteLines 1, module.CountOfLines
                module.AddFromString moduleText
               End If
        Next
    End Sub
    Administrator's note: Please take the time to review our rules. There aren't many, and they are all important. Our guidelines recommend code tags. I have added them for you this time because you are a new member. --6StringJazzer

    User on 2010 is getting this error
    Run-time error '-2147417848 (80010108)':
    Method 'AddFromString' of object '_CodeModule' failed

    Any help would be appreciated !
    Last edited by 6StringJazzer; 09-16-2024 at 10:21 AM.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,279

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Do users have the "Trust access to the VBA project object model" option checked ?

    Options > Trust Center > Trust Center Settings > Macros Settings > Trust access to the VBA project object model

  3. #3
    Registered User
    Join Date
    09-16-2024
    Location
    Stafford, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Thank you for responding, yes that is enabled. It is already a required setting for users to be able to upload their data using the VBA inherited from Oracle so is pushed out to all users using group policy updates.

  4. #4
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,093

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Can you add an error handler and find out which module throws the error?

  5. #5
    Registered User
    Join Date
    09-16-2024
    Location
    Stafford, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Hi, thank you but I am new to VBA so I only know how to add this

    Sub UpdateVBA()
    ' *** Update VBA ***
        
    On Error GoTo errHandler 'error handler
        
        Dim component As Object
        For Each component In ActiveWorkbook.VBProject.VBComponents
                Dim module As Object
                Set module = component.CodeModule
               If module.CountOfLines > 0 Then
                Dim moduleText As String
                moduleText = module.Lines(1, module.CountOfLines)
                moduleText = Replace(moduleText, "//ebseprod.nch.com:443/", "//eurprod.nch.com:443/")
                
                moduleText = Replace(moduleText, "C2039321.EBSEPROD", "NCHEBSDBS151.NCH.COM.EURPROD")
                moduleText = Replace(moduleText, "EBSEPROD", "EURPROD")
                moduleText = Replace(moduleText, "ebseprod", "eurprod")
    
                module.DeleteLines 1, module.CountOfLines
                module.AddFromString moduleText
               End If
        Next
    
    procDone: 'error handler
    Exit Sub 'error handler
    errHandler: 'error handler
    MsgBox Err.Number & ": " & Err.Description 'error handler
    Resume procDone 'error handler
    
    End Sub
    All that did was to pop up a message box
    "'-2147417848: Method 'AddFromString' of object '_CodeMudule' failed"

  6. #6
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,093

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Try this. It should give you the module name and the line which generated the error

    Sub UpdateVBA()
          ' *** Update VBA ***
              
    10    On Error GoTo errHandler 'error handler
              
              Dim component As Object
    20        For Each component In ActiveWorkbook.VBProject.VBComponents
                      Dim module As Object
    30                Set module = component.CodeModule
    
    40               If module.CountOfLines > 0 Then
                      Dim moduleText As String
    50                moduleText = module.Lines(1, module.CountOfLines)
    60                moduleText = Replace(moduleText, "//eurprod.nch.com:443/", "//eurprod.nch.com:443/")
                      
    70                moduleText = Replace(moduleText, "NCHEBSDBS151.NCH.COM.EURPROD", "NCHEBSDBS151.NCH.COM.EURPROD")
    80                moduleText = Replace(moduleText, "EURPROD", "EURPROD")
    90                moduleText = Replace(moduleText, "eurprod", "eurprod")
    
    100               module.DeleteLines 1, module.CountOfLines
    110               module.AddFromString moduleText
    120              End If
    130       Next
    
    140   Exit Sub 'error handler
    errHandler: 'error handler
    
    150   MsgBox Err.Number & ": " & Err.Description & vbNewLine & "Error on line " & Erl & ", Mod:" & module.Name
    
    End Sub

  7. #7
    Registered User
    Join Date
    09-16-2024
    Location
    Stafford, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Thank you, I can actually understand what you have suggested (from my 1980's basic days!)

    Now message is

    -2147417848: Method 'AddFromString' of object '_CodeMudule' failed
    Error on 110, Mod:bnemain

    bnemain is an existing module embedded in the Oracle template when downloaded to local machine

    As stated previously the error does not happen with myself using Excel 2016, only with user on 2010

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Does the user get any errors if they compile the code after downloading the template?
    Everyone who confuses correlation and causation ends up dead.

  9. #9
    Registered User
    Join Date
    09-16-2024
    Location
    Stafford, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Quote Originally Posted by romperstomper View Post
    Does the user get any errors if they compile the code after downloading the template?
    Thanks for the reply, we cannot test that scenario now because we have moved to the new database so if a new template is downloaded it has the correct DB name/URL already in the Oracle module.

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,015

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Then do they get any errors when compiling an existing workbook - i.e. one of the ones you are trying to fix?

    I hope you have now parameterised the code so you don't have to do this again when things inevitably change next time...

  11. #11
    Registered User
    Join Date
    09-16-2024
    Location
    Stafford, England
    MS-Off Ver
    2016
    Posts
    6

    Re: Run-time error '-2147417848' Method 'AddFromString'

    Quote Originally Posted by romperstomper View Post
    Then do they get any errors when compiling an existing workbook - i.e. one of the ones you are trying to fix?

    I hope you have now parameterised the code so you don't have to do this again when things inevitably change next time...
    Thank you I will parameterize in future. The error is happening on existing workbooks as downloading new templates is painful because there are hundreds and they all have several worksheets with links etc.

    There are 2 type of Oracle templates (old & new), one with DB name in the VBA, the others have the DB name in the custom properties, so I had an additional macro for this.
    eg ActiveWorkbook.CustomDocumentProperties("host").Value = 'newdbname"

    The error was happening in the first code (VBA change) for the second scenario (using custom properties) where the DB name did not exist in the VB. I have added an On Error Resume Next so it skips this error and moves on the changing the properties.
    Users are now able to use my code without error.

    Thank you all for replying, hopefully we will not move servers again very soon!

+ 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. VBA Help - Runtime error -2147417848 (80010108) - Method has failed
    By PTSD in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 02-02-2024, 05:40 AM
  2. Run-time error -2147417848 (80010108) Method "Show" of object failed
    By brockbaker27 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-14-2021, 11:03 AM
  3. [SOLVED] Run-time error '-2147417848(80010108) : Method 'Formula' of object 'Range' failed
    By Norlina Deli in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 01-24-2019, 05:54 AM
  4. [SOLVED] run time error -2147417848 (80010108) Method 'Formula' on object 'Series' failed
    By dluhut in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-12-2016, 02:11 PM
  5. Run-time error '-2147417848 (80010108)' Method 'Formula' of object 'Range failed
    By JessKong1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2016, 02:02 AM
  6. Run-time error -2147417848 (80010108) Method Value of object Range failed
    By Arito in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-17-2015, 02:10 PM
  7. Replies: 7
    Last Post: 08-24-2005, 11:05 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